16 lines
353 B
TypeScript
16 lines
353 B
TypeScript
/**
|
||
* 从最小单位(step)中推导小数位数
|
||
*
|
||
* "1.00000000" -> 0
|
||
* "0.01000000" -> 2
|
||
* "0.00010000" -> 4
|
||
*/
|
||
export function getDecimalPlacesFromStep(step: string): number {
|
||
const [, decimal = ""] = step.split(".")
|
||
|
||
if (!decimal) return 0
|
||
|
||
const index = decimal.search(/[1-9]/)
|
||
return index === -1 ? 0 : index + 1
|
||
}
|