adamwdraper / Numeral-js

A javascript library for formatting and manipulating numbers.
http://numeraljs.com
MIT License
9.66k stars 927 forks source link

Strange formatting behavior #784

Open 0xalecks opened 1 year ago

0xalecks commented 1 year ago
console.log(numeral('0.000000001').format('0.000000000')); // NaN
console.log(numeral('0.000000011').format('0.000000000')); // NaN
console.log(numeral('0.000000111').format('0.000000000')); // NaN
console.log(numeral('0.000001111').format('0.000000000')); // 0.000001111

console.log(numeral('0.00000001').format('0.00000000'));   // NaN
console.log(numeral('0.00000011').format('0.00000000'));   // NaN
console.log(numeral('0.00000111').format('0.00000000'));   // 0.00000111

console.log(numeral('0.0000001').format('0.0000000'));     // NaN
console.log(numeral('0.0000011').format('0.0000000'));     // 0.0000011
console.log(numeral('0.0000111').format('0.0000000'));     // 0.0000111

It seems any value less than 1e-6 is considered NaN, but higher values with more precision work?

sunxi1997 commented 1 year ago

我也遇到了这个问题, 只有小数点后连续6位都是0时才会出现, 似乎是因为 js 会把这种数字强制使用科学计数法 image