# Node-red-contrib-counter

**URL:** <https://discourse.nodered.org/t/node-red-contrib-counter/28360>\
**Category:** General\
**Created:** [15 June 2020 14:41 UTC](https://discourse.nodered.org/t/node-red-contrib-counter/28360 "2020-06-15T14:41:26Z")\
**Posts on this page:** 1\
**Showing post:** 27

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 July 2020 10:15 UTC](https://discourse.nodered.org/t/node-red-contrib-counter/28360/27 "2020-07-13T10:15:04Z")

</div>

@kxn25  
UPDATE: after more research, this is not a bug in node-red-contrib-counter, it is an issue with how javascript handles decimals. Ther is a great explaination at [http://adripofjavascript.com/blog/drips/avoiding-problems-with-decimal-math-in-javascript.html](http://adripofjavascript.com/blog/drips/avoiding-problems-with-decimal-math-in-javascript.html)

The solution for you is to use whole numbers and device by 1000 when you want to use it. Here is an updated flow as an example:

 ![Screen Shot 2020-07-13 at 6.13.44 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/6/36dd80ce9146de097a89b72ecb2faafd968324d1.png)

```auto
[{"id":"33f1976d.907798","type":"inject","z":"674b54ba.c0ebf4","name":"increment","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":420,"wires":[["381f2c71.f7670c"]]},{"id":"381f2c71.f7670c","type":"counter","z":"674b54ba.c0ebf4","name":"","init":"0","step":"1","lower":"","upper":"","mode":"increment","outputs":"1","x":540,"y":480,"wires":[["295107a1.67cc58","b98146ef.0ab288"]]},{"id":"b98146ef.0ab288","type":"change","z":"674b54ba.c0ebf4","name":"flow.counter = count ","rules":[{"t":"set","p":"counter","pt":"flow","to":"count","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"count/1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":480,"wires":[["ea0c2a5f.fcd858"]]},{"id":"9b5e941a.b9cbf","type":"inject","z":"674b54ba.c0ebf4","name":"reset","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":480,"wires":[["6f0843b0.c5be9c"]]},{"id":"6f0843b0.c5be9c","type":"change","z":"674b54ba.c0ebf4","name":"delete flow.counter, reset count","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"},{"t":"delete","p":"counter","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":480,"wires":[["381f2c71.f7670c"]]},{"id":"295107a1.67cc58","type":"debug","z":"674b54ba.c0ebf4","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"count","targetType":"msg","x":710,"y":420,"wires":[]},{"id":"ea0c2a5f.fcd858","type":"debug","z":"674b54ba.c0ebf4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"count","statusType":"msg","x":930,"y":480,"wires":[]}]

```

---

_[View the full topic](https://discourse.nodered.org/t/node-red-contrib-counter/28360)._
