Page 1 of 1
[Issue] Rounding - Calc field
Posted: Thu Feb 15, 2018 3:56 pm
by toms
Hi,
A calc field calculates the sum of hours divided by 8.4.
75.60 / 8.4 = 9.00 but 8.99 is displayed. How to show the exact/accurate value?
calc_rounding_issue.png
Re: [Issue] Rounding - Calc field
Posted: Thu Feb 15, 2018 9:39 pm
by admin
toms,
I have added
Math.round().
round_added.PNG
You'll need to get the latest from Github and then Update.
Steven
Re: [Issue] Rounding - Calc field
Posted: Fri Feb 16, 2018 4:50 am
by toms
Steven,
Thanks for adding the Round() function. That has solved my rounding issue.
Edit: Now figures are rounded where no rounding should happen (e.g. 27.60 / 8.4 is rounded to 3 but it should be output as 3.33)
Re: [Issue] Rounding - Calc field
Posted: Fri Feb 16, 2018 5:34 am
by toms
Steven,
The rounding could be fixed with toFixed().
I did some testing:
var v = 0;
var u = 8.4 * 9;
v = parseFloat(Number(v) + Number(u)).toPrecision(10)
var t = v / 8.4;
// 75.60000000 / 8.4
print(t); // 8.999999 <--- incorrect rounding
t = + t.toFixed(2); //
2 to be replaced with the precision of the calc field ( data-nu-format="N|1000.
00" )
print(t); // 9 <-- correct rounding
Test it for yourself:
http://rextester.com/GIF55847
Re: [Issue] Rounding - Calc field
Posted: Fri Feb 16, 2018 6:25 am
by admin
toms,
Adding rounding was a good idea.
For decimal places, people can always do this...
decimal_places.PNG
If someone needs something more complicated they can use Javascript like the rest of us.
Steven
Re: [Issue] Rounding - Calc field
Posted: Fri Feb 16, 2018 8:11 am
by toms
Steven,
When you are dealing with things that are counted, rounding errors look "ugly" when you expect a whole number without fractions.
In my case, 8.9999 is not only arithmetically wrong but irritating. The correct result is 9 days, nothing more or less.
In accounting, when dealing with financial figures, it might be a different story.
Having said that, your last post gave me an idea.
This formula seems to do the job:
nuTotal('sub_dates.hours') / 8.4 + 0.000000000000001
Re: [Issue] Rounding - Calc field
Posted: Fri Feb 16, 2018 8:43 pm
by admin
.