i´ve build myself a little dashboard for fuel prices around me.
I can get the normal prices from Clever Tanken while i get some of the premium prices directly from the API of the fuel station.
While i get the full price to the third decimal place from the fuel stations APIs, i only get two decimal places from Clever Tanken, as they use two different places for price and subprice.
I recently learned how to modify values with JS transformation and wanted to use this to add 0.009 to the values i receive from Clever Tanken.
This works fine for some of the values but some have a strange behavior.
Channel configuration in the http binding REGEX:.*<span id="current-price-4">(.*)<\/span>.*<sup id="suffix-price-4">.*∩JS:add009.js
And here are some outputs of the log:
Item 'ctJetSuper' changed from 1.869 to 1.819
Item 'ctShellSuper' changed from 1.879 to 1.869
Item 'ctShellVPower' changed from 2.129 to 2.1189999999999998
Item 'ctJetSuperPlus' changed from 1.9089999999999998 to 1.849
Item 'ctJetSuper' changed from 1.819 to 1.759
Item 'ctJetSuperPlus' changed from 1.849 to 1.839
Item 'ctJetSuper' changed from 1.759 to 1.7489999999999999
It´s not critical because i fixed the decimal places in Grafana to 3 and it display the correct values.
I still would like to understand what is causing this issue and if it can be resolved.
Sometimes that can be easier or more straight forward to use.
It’s part of programming in general and you will see it any time you are using a programming language that uses IEE 754 floating point representation (almost all of them) which cannot represent every single floating point number exactly.
I don’t want anyone thinking that this is unique to just openHAB JS transformations.