ice.fo.utils
Version:
14 lines (9 loc) • 375 B
JavaScript
export default function formatTextNumber(value, decimal = 0, emptyValue = '0') {
if (!value) {
return emptyValue;
}
value = `${value}`;
const hasEndDot = (decimal && value.endsWith('.')) || '';
const num = !decimal ? parseInt(value, 10) : parseFloat(value);
return num.toLocaleString(undefined, { maximumFractionDigits: decimal }) + (hasEndDot && '.');
}