question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

numeral format for small numbers returns NaN

See original GitHub issue

For example numeral(0.0000000048).format('0') // NaN

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:21
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
vcarlcommented, Jul 25, 2018

Same issue, appears to be any number with 6 or more leading 0s.

numeral(.0000001).format('0')
> "NaN"
numeral(.000001).format('0')
> "0"
numeral(.0000005).format('0')
> "NaN"
numeral(.0000009).format('0')
> "NaN"
numeral(.0000010).format('0')
> "0"
numeral(.0000015).format('0')
> "0"

Incidentally, that appears to be when the chrome console starts displaying numbers in exponential form.

.000001
> 0.000001
.0000001
> 1e-7
0reactions
am05mhzcommented, Aug 26, 2022

since this repo is not updated anymore, and still have this bug, and if you still wish to use the latest version, you can do this work around:

function formatSmall(val, format) {
  if (val > 0 && val < 1e-6){
    // make the number 100 times greater, then just replace 0.0 with additional 2 zeroes (from 100)
    return numeral(val * 100).format(format).replace('0.0', '0.000');
  }
  return numeral(val).format(format);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Numeral.js
A javascript library for formatting and manipulating numbers. ... Numeral takes numbers or strings that it trys to convert into a number.
Read more >
Sum numbers returns NaN - javascript - Stack Overflow
I'm trying to do a sum of numbers inside div's, so, I did:.
Read more >
NaN - Wikipedia
In computing, NaN standing for Not a Number, is a member of a numeric data type that can be interpreted as a value...
Read more >
Math.floor() - JavaScript - MDN Web Docs
A number. Return value. The largest integer smaller than or equal to x . It's the same value as - ...
Read more >
JavaScript parseFloat() Function - GeeksforGeeks
If the string does not contain a numeral value or If the first character of the string is not a Number then it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found