FIX + EXTEND: siPrefix
This commit is contained in:
parent
ce4c8de6f8
commit
54b4d4d3e6
@ -1,4 +1,4 @@
|
||||
export const SI_PREFIXES: string[] = ['f', 'p', 'n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'E', 'P'];
|
||||
export const SI_PREFIXES: string[] = ['q', 'r', 'y', 'z', 'a', 'f', 'p', 'n', 'µ', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'R', 'Q'];
|
||||
|
||||
export function siPrefix(value: number, unit: string, minDigits: number): string {
|
||||
if (value === 0) {
|
||||
@ -7,8 +7,8 @@ export function siPrefix(value: number, unit: string, minDigits: number): string
|
||||
const negative = value < 0;
|
||||
value = negative ? -value : value;
|
||||
const exp0 = Math.log10(value);
|
||||
const group = Math.floor(exp0 / 3);
|
||||
const index = group + 5;
|
||||
const group = Math.max(-10, Math.min(+10, Math.floor(exp0 / 3)));
|
||||
const index = group + 10;
|
||||
const prefix = SI_PREFIXES[index];
|
||||
const exp1 = group * 3;
|
||||
const factor = Math.pow(10, -exp1);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user