This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
Homey can't count
Mathijs
Member
start at 0 homey counts like this
0.1
0.2
0.30000000000004
0.4
0.5
etc
Same when I decrement. Anybody any idea why Homey hates the number 3?
Comments
the answer is probably because floating point values are used, then 2 + 1 is not always exactly 3 but maybe 0.30000000000004 (caused by rounding in calculations), but I'm not an expert on this.
I tested with Homeys build in Logic cards and this gives the same, 0.1 0.2 0.30000000000004 , 0.5, 0.6, 0.7, 0.7999999999.....
looks like something in the core of Node.JS / JavaScript!
googled it and found it is explained in:
https://stackoverflow.com/questions/588004/is-floating-point-math-broken
So, nothing Athom can do about it except rounding the presentation to give normal users a expected presentation.
But this could give other unwanted side effects in the end with complex calculations.
The Execute MathJs Expresion accepts the formula "round(WAARDE * 10) / 10" but do I replace WAARDE with my variable? And what should be inserted in the Name field
in addition, I think the formula used in the referenced commment is better; "round(volume,2)"
The name field is the name of a Better Logic variable