UNPKG

@beenotung/tslib

Version:
26 lines (25 loc) 690 B
"use strict"; /** * Created by beenotung on 4/23/17. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.fromLocaleString = fromLocaleString; exports.countFractionDigits = countFractionDigits; function fromLocaleString(str) { const num = +str.replaceAll(',', ''); if (num.toLocaleString() === str) { return num; } throw new Error('failed to parse locale string into number'); } function countFractionDigits(num) { let str = num.toString(); if (str.includes('e')) { str = str.split('e')[0]; } const dotIndex = str.indexOf('.'); if (dotIndex === -1) { return 0; } return str.length - dotIndex - 1; }