Calculation with decimals not properly

Hi there,

I have made a calculation in Codeless to count a one decimal value.
Unfortunately, there is a strange behaviour happening sometimes where the output becomes 1e-14 long.
Although I am only calculating with 1 decimal behind the comma. (0.6 times my counter value)
The newValue will become 4.799999999997 or something similar sometimes.
The fix that I made is not that nice, maybe you have a better solution.

Application ID

9899A2F8-3DC6-5C94-FF20-89FD58136300

Hi @Robin_van_Kuijk

Did your solution work or do you still face the problem you described?

Regards,
Inna

Hi, @Robin_van_Kuijk

Unfortunately, but this problem not on our side. That because JavaScript(your codeless logic transpile to this) as the language for calculating float numbers not perfect.

You can read more here

Advice for you - keep the attention while calculating and try to calculate all as an integer, and after all the operations make answer in the decimal numbers.

Also, I see you try to solve it using very big numbers, don’t forget about one more JS problem - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER

Regards, Dima

Thanks for the reply both of you!
I am not sure what you mean with the operations to make the answer in decimal numbers,
but I think I am going to solve this issue on the application side (android studio).
I did not know that JavaScript doesn’t calculate float numbers perfectly, so thanks for making that clear.
As for I can tell, decimal numbers are wrong in 20% of the cases
(which makes it strange to me that 80% does work perfect haha)
Since I needed it as a type of money value, like 12,50 , 4,20 and so on,
but I will just use the float that Codeless generates and continue with that.

Best regards,
Robin