-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Precision issue when sum array #333
Comments
I'm afraid this is just the nasty nature of floats. Here's what happens if you do the same thing in Python:
|
If you want precision, you have to adapt your processing a little. With this input {
"data": [
150.40,
140.51
]
} you can apply this transformation:
The result is: {
"roundnum" : 290.91
} |
Try this, to see the changes applied:
It gives you: {
"round1" : 290.90999999999997,
"round2" : 290.9,
"roundnum" : 290.91
} |
do we have a decimal type to avoid the precision issue ? |
' + 0.5 ' is only valid for the current nunmber... if I change the number, it will not work |
Actually, it is correct for positive sums. @jerrybyte Try this: Input: {
"data": [
[
150.40,
140.51
],
[
150.40,
140.51,
10.32
],
[
150.40,
140.51,
10.32,
15.83
]
]
} With this transformation:
The result is: [ {
"sum" : 290.90999999999997,
"sumWith2Digits" : 290.9,
"sumRoundedTo2Digits" : 290.91
}, {
"sum" : 301.22999999999996,
"sumWith2Digits" : 301.22,
"sumRoundedTo2Digits" : 301.23
}, {
"sum" : 317.05999999999995,
"sumWith2Digits" : 317.05,
"sumRoundedTo2Digits" : 317.06
} ] |
What precision are you looking for? |
we want to sum the array, but when we used sum() function, it give a wrong result.
Expression : "roundnum" : sum([150.40, 140.51]),
Result: "roundnum" : 290.90999999999997,
The text was updated successfully, but these errors were encountered: