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.

how to switch rounding off

See original GitHub issue

Hi, when I use the numeral I want to format the number to 0.00a but it’s rounding the last digit, I don’t want to do the rounding and I don’t find any document about it. value: 4986444.0 format: $0.00a return: $4.99m expected: $4.98m

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

30reactions
Silviu-Mariancommented, May 9, 2017

numeral().format() accepts a 2nd parameter which is the rounding function to use.

In your case, you probably want Math.floor - numeral(4986444.0).format('0.00a', Math.floor)

You can also use bitwise negation like this numeral(4986444.0).format('0.00a', n => ~~n)

I hope this helps

5reactions
Silviu-Mariancommented, May 16, 2017

numeral.fn._format = numeral.fn.format;
numeral.fn.format = function (a, b) { return numeral.fn._format.call(this, a, b || numeral._.defaultRoundingFunction); };

numeral._.defaultRoundingFunction = Math.round;
numeral.setDefaultRoundingFunction = (fn) => { numeral._.defaultRoundingFunction = fn || numeral._.defaultRoundingFunction; }

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Round a number to the decimal places I want - Microsoft Support
In number, type the number you are rounding down. In num_digits, type 0 to round the number up to the nearest whole number....
Read more >
How to Get Excel to Stop Rounding Your Numbers | Excelchat
To stop Excel from rounding currencies, format the decimal places to “3 or more”. This way, the precision and accuracy of our data...
Read more >
Rounding Numbers - Math is Fun
How to Round Numbers · Decide which is the last digit to keep · Leave it the same if the next digit is...
Read more >
Rules for Rounding Off - Chemteam.info
We can correct for this problem by changing the rule for rounding 5 rounding "off" (keeping the number the same) in fifty percent...
Read more >
Rounding Numbers Calculator
Rounding calculator to round numbers up or down to any decimal place. Choose ones to round a number to the nearest dollar. Choose...
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