dkern / node-red-counter

A Node-RED node to increment a count.
Other
8 stars 9 forks source link

Counter not working for decimals #19

Open kayman-mk opened 4 years ago

kayman-mk commented 4 years ago

Initial counter: 4105.123 Increment: 0.001

After incrementing the counter 5 times I expect to get the value 4105.128. But instead 4105.128000000001 is reported. As far as I know implementing the counter as float will cause problems. Quickfix: Math.round(counter*1000)/1000 would fix this. But the number of decimals has to be calculated to set the correct factor (1000 for 3 decimals).

dkern commented 4 years ago

It's a known issue while working with numbers like that in JS. I would not know a good fix, without a setting for desired decimals. But I don#t think I like to add that, because it will confuse most users. So for now, I would say, use it with decimals at your own risk. ;)

A fix for you could also be to add a JS node behind the counter, and do the rounding by yourself.