import libConfig from './libConfig' const mathFunctionMap: { [type: string]: (x: number) => number } = { up: Math.ceil, down: Math.floor, off: Math.round, '': Math.round, } export default function getDisplayRoundNumber (value: number, rounding: IOrderRounding = libConfig.rounding): string { if (value == null) return '0' value = Number(value) const mathFunction = mathFunctionMap[rounding.type] if (mathFunction == null) { return value.toFixed(rounding.digits) } const digitsAdjust = Math.pow(10, rounding.digits) return (mathFunction(value * digitsAdjust) / digitsAdjust).toFixed(rounding.digits) }