untitled notebook

node v10.24.1
version: 1.0.0
endpointsharetweet
const leftpad = require('leftpad'); const toFixedLong = (input, decimalPoints = 1) => { const floor = Math.floor(input) let x = floor let output = '' while (x >= 1000) { output = ',' + leftpad(x % 1000, 3, '0') + output; x = Math.floor(x / 1000); } return '' + x + output + (input - floor).toFixed(decimalPoints).slice(1); } const input = 1234000000000000.245 // 1,234,000,000,000,000.245 const inputB = 1.3986383939661338e+308 console.log(toFixedLong(input)) console.log(toFixedLong(inputB))
Loading…

no comments

    sign in to comment