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?
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
[Issue] Rounding - Calc field
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
[Issue] Rounding - Calc field
You do not have the required permissions to view the files attached to this post.
Re: [Issue] Rounding - Calc field
toms,
I have added Math.round().
You'll need to get the latest from Github and then Update.
Steven
I have added Math.round().
You'll need to get the latest from Github and then Update.
Steven
You do not have the required permissions to view the files attached to this post.
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: [Issue] Rounding - Calc field
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)
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)
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: [Issue] Rounding - Calc field
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
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
toms,
Adding rounding was a good idea.
For decimal places, people can always do this...
If someone needs something more complicated they can use Javascript like the rest of us.
Steven
Adding rounding was a good idea.
For decimal places, people can always do this...
If someone needs something more complicated they can use Javascript like the rest of us.
Steven
You do not have the required permissions to view the files attached to this post.
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: [Issue] Rounding - Calc field
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
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