Numeral-js icon indicating copy to clipboard operation
Numeral-js copied to clipboard

formating a number which is very very small will get NaN

Open yiliang114 opened this issue 4 years ago • 2 comments

import numeral from 'numeral';
console.log(
  'numeral',
  numeral('-0.0000000008851743227289433')
    .divide(0.01)
    .format('0.0'),
  numeral('-0.000000009433')
    .divide(0.01)
    .format('0.0'),
);

// numeral NaN 0.0

yiliang114 avatar Dec 08 '20 08:12 yiliang114

+1, I am facing the same issue when try to enter long integer (more than 22 digit.) Ex: 12345678901234567890123

UmeshRavariya avatar Jan 06 '21 08:01 UmeshRavariya

numbro(-0.00000000008851743227289433).format()
// "-8.851743227289433e-11"
numbro(12345678901234567890123).format()
// "1.2345678901234568e+22"

Maybe numbro is worth a try?

Disclosure: I'm numbro author

BenjaminVanRyseghem avatar Mar 30 '21 12:03 BenjaminVanRyseghem