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.

Homey can't count



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

  • JPeJPe Member
    After Increment use a card "Execute MathJs Expresion" with  round(WAARDE * 10) / 10  , will give you 1 dicimal always
  • JPe said:
    After Increment use a card "Execute MathJs Expresion" with  round(WAARDE * 10) / 10  , will give you 1 dicimal always
    That is not realy a answer to his question.... I wonder to why  homey adds more than 1 if you ask home +1
  • JPeJPe Member
    edited August 2017
    sorry, it was not exactly an answer, but more a work around. 
    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.
  • GeurtDijkerGeurtDijker Member
    edited August 2017
    You are using Better Logic,
    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.
  • MathijsMathijs Member
    edited August 2017
    Damn.... that will be a complex fix for a simple problem.  I use this to set the volume of Sonos and it really does not like the volume set to 3.0000000004. 

    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
  • @Mathijs you can simply use the same tags in your calculation, see below example: https://forum.athom.com/discussion/comment/55876/#Comment_55876

    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
  • Thanks!
Sign In or Register to comment.