Thomas G. Lopes
pricing info (#97)
1979653 unverified
raw
history blame
332 Bytes
export function atLeastNDecimals(num: number, minDecimals: number): string {
return num.toFixed(Math.max(minDecimals, getDecimalPlaces(num)));
}
function getDecimalPlaces(num: number): number {
const str = num.toString();
const decimalIndex = str.indexOf(".");
return decimalIndex === -1 ? 0 : str.length - decimalIndex - 1;
}