Open wjcrowcroft opened 13 years ago
Just a thought, since I've seen this before. You can do this first by scaling the number.
floor(0.615*100)/100
That will "round" 0.615 to 0.61.
Gah, that didn't format properly. Let's try it again
floor(0.615*100)/100 should return 0.61
Working on a solution in a branch. I'll let you know when I get somewhere interesting.
This sounds like the way accounting.toFixed
works, too, so have a look at that one. Would love to see anything you come up with.
Is there any particular reason why checkPrecision() forces a positive number? If we can use negative numbers, then we'll be able to round to the tens, hundreds, etc. I'm about to change it and want to be able to address any potential fallout. I saw it used in formatNumber for determining whether or not to add on a decimal, but nowhere else did it appear that a negative number would cause a break.
Thanks!
On Tue, Oct 18, 2011 at 1:16 PM, Joss Crowcroft reply@reply.github.com wrote:
This sounds like the way
accounting.toFixed
works, too, so have a look at that one. Would love to see anything you come up with.Reply to this email directly or view it on GitHub: https://github.com/josscrowcroft/accounting.js/issues/13#issuecomment-2444667
Michael Cordingley 740.707.7809
Yep. I looked at accounting.toFixed
as well. Pull request on this issue can be found here: https://github.com/josscrowcroft/accounting.js/pull/31
Rounding should be an option - always up, always down, or [default] nearest neighbour.
Can anybody weigh in on what the options for
rounding
would be labelled?floor
andceil
possibly don't apply since they imply rounding up/down to integers, but rounding in our case also applies to floating points, eg0.615 > 0.62
Any thoughts, do share. Cheers