# Calculate the difference with adjusted values

**URL:** <https://discourse.nodered.org/t/calculate-the-difference-with-adjusted-values/82797>\
**Category:** General\
**Created:** [12 November 2023 11:37 UTC](https://discourse.nodered.org/t/calculate-the-difference-with-adjusted-values/82797 "2023-11-12T11:37:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![einfach112](https://avatars.discourse-cdn.com/v4/letter/e/3da27b/32.png) [@einfach112](https://discourse.nodered.org/u/einfach112)\
**Post date:** [12 November 2023 11:37 UTC](https://discourse.nodered.org/t/calculate-the-difference-with-adjusted-values/82797/1 "2023-11-12T11:37:31Z")

</div>

Hello everyone,  
I would like to measure how much real green electricity I put into my car. I currently have 2 values ​​available to me.  
Value 1  
comes per second and is quite ok so far. E.g. I have a surplus, the value looks like this: -123 \<- This means that I currently have a surplus of -123 watts.  
123 would mean that I don't have any surplus and that I currently get my electricity from the power grid.  
Unfortunately, the second value is currently a bit complicated. I get it from my socket. The value is always positive because I charge my car there. The problem is that the value currently looks like this in reference to above:  
123555  
The actual wattage is followed by another 3 digits. First I would have to manage to shorten this number by 3 digits.  
Since I would then have the value that the car is charging, I could use this value to check whether I am currently refueling green, half green or not at all via the solar system.  
Can someone tell me how I can do this? It would be enough if I managed to put a comma in three places at the end! It would be important from behind because the value in front of it can also have several digits

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 November 2023 11:58 UTC](https://discourse.nodered.org/t/calculate-the-difference-with-adjusted-values/82797/2 "2023-11-12T11:58:46Z")

</div>

Is 123555 a string or a number? and is -123 a string or a number? show debug outputs of these. strings would be red and numbers blue.

---

<div class="post-metadata">

**Author:** ![einfach112](https://avatars.discourse-cdn.com/v4/letter/e/3da27b/32.png) [@einfach112](https://discourse.nodered.org/u/einfach112)\
**Post date:** [12 November 2023 12:00 UTC](https://discourse.nodered.org/t/calculate-the-difference-with-adjusted-values/82797/3 "2023-11-12T12:00:31Z")

</div>

anyone arte blue...

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 November 2023 12:03 UTC](https://discourse.nodered.org/t/calculate-the-difference-with-adjusted-values/82797/4 "2023-11-12T12:03:52Z")

</div>

Then using a change node and JSONata

```auto
[{"id":"e11d3d5bc71875ce","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"charge","payload":"123555","payloadType":"num","x":180,"y":1460,"wires":[["d6bec0522bf975dc"]]},{"id":"d6bec0522bf975dc","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$floor($$.payload/1000)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":1460,"wires":[["b195995ea937cdde"]]},{"id":"b195995ea937cdde","type":"debug","z":"d1395164b4eec73e","name":"debug 2456","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":1380,"wires":[]}]

```

If you divide 123555 by 1000 and $floor() it, result is 123

You could also use JSONata direct in a switch node property config.

---

<div class="post-metadata">

**Author:** ![einfach112](https://avatars.discourse-cdn.com/v4/letter/e/3da27b/32.png) [@einfach112](https://discourse.nodered.org/u/einfach112)\
**Post date:** [12 November 2023 12:07 UTC](https://discourse.nodered.org/t/calculate-the-difference-with-adjusted-values/82797/5 "2023-11-12T12:07:19Z")

</div>

Thank you! it works fine

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 November 2023 12:07 UTC](https://discourse.nodered.org/t/calculate-the-difference-with-adjusted-values/82797/6 "2023-11-26T12:07:34Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
