function toDecimal(x) { if (x !== '.') { let f = Math.round(x * 100) / 100; let s = f.toString(); let rs = s.indexOf('.'); if (rs <= 0) { rs = s.length; s += '.'; } while (s.length <= rs + 2) { s += '0'; } return s; } else { return '0.00'; } }