FIX: siPrefix negative values
This commit is contained in:
parent
eba8d51e3e
commit
c68217b595
@ -4,6 +4,8 @@ export function siPrefix(value: number, unit: string, minDigits: number): string
|
||||
if (value === 0) {
|
||||
return `0${unit}`;
|
||||
}
|
||||
const negative = value < 0;
|
||||
value = negative ? -value : value;
|
||||
const exp0 = Math.log10(value);
|
||||
const group = Math.floor(exp0 / 3);
|
||||
const index = group + 5;
|
||||
@ -14,5 +16,5 @@ export function siPrefix(value: number, unit: string, minDigits: number): string
|
||||
const hasDigits = Math.floor(Math.log10(newValue)) + 1;
|
||||
const decimals = Math.max(0, minDigits - hasDigits);
|
||||
const newValueStr2 = newValue.toFixed(decimals);
|
||||
return `${newValueStr2}${prefix}${unit}`;
|
||||
return `${negative ? '-' : ''}${newValueStr2}${prefix}${unit}`;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user