feat: 完成....
This commit is contained in:
15
tonesc-red-packet/lib/currency.ts
Normal file
15
tonesc-red-packet/lib/currency.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 从最小单位(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
|
||||
}
|
||||
Reference in New Issue
Block a user