Files
tonesc-red-packet/tonesc-red-packet/lib/currency.ts
2026-01-07 23:22:15 +08:00

16 lines
353 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 从最小单位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
}