Skip to content

Commit 8fb8816

Browse files
committed
Fix some code
1 parent a3db278 commit 8fb8816

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/components/NumericDisplay/NumericDisplay.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@ function formatNumber(number = 0, shortForm = true) {
4040
).toString(); //return number rounded to nearest integer
4141
} else {
4242
//if number is 1 thousand or more
43-
const mantissa = parseFloat(number) / Math.pow(10, exponent3); //get the mantissa value from 1 to 999
43+
const mantissa = parseFloat(number.toString()) / Math.pow(10, exponent3); //get the mantissa value from 1 to 999
4444
const roundedNumber = mantissa.toPrecision(3); //round number to 3 significant figures
4545
return (
46-
Math.min(999, Math.max(-999, Number(roundedNumber))).toPrecision(3) +
47-
prefixes[exponent3 / 3]
46+
Math.min(
47+
999,
48+
Math.max(
49+
-999,
50+
Number(Math.abs(roundedNumber) * Math.sign(roundedNumber)),
51+
),
52+
).toPrecision(3) + prefixes[exponent3 / 3]
4853
); //return coefficient of engineering notation with numeric prefix
4954
}
5055
} else {

0 commit comments

Comments
 (0)