# Problems with converting numeric items

**URL:** <https://community.openhab.org/t/problems-with-converting-numeric-items/55336>\
**Category:** Beginners\
**Created:** [October 31, 2018, 8:03pm UTC](https://community.openhab.org/t/problems-with-converting-numeric-items/55336 "2018-10-31T20:03:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomhag](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@tomhag](https://community.openhab.org/u/tomhag)\
**Post date:** [October 31, 2018, 8:03pm UTC](https://community.openhab.org/t/problems-with-converting-numeric-items/55336/1 "2018-10-31T20:03:09Z")

</div>

I have a project were im reading alot of modbus values.  
This numbers comes inn as value with 4 number were you need to devide it by 100 to get the right number (1000= 10,00 celsius)

For this i have been using Javascript Transformation as suggested on forum and modbus driver. I have used the Javascript transformation on items file like this.

```csv
Number V3601Utetemp "Temperatur utetemp [JS(devideTemp.js):%s]" <temperature> { modbus="input:23" }

```

This works for basic UI, but for logging and habpanel this does not work.

This should probably be in the driver, but how do i do that?

.js

```php
(function(i){
	return (i / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + '°C';
})(input)

```

Basic UI - This works  
 ![bilde](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/7/b/7bad6675b16318fb6243b283d1d1e1580856f484.png)

Logging (RRDJ4)

 ![bilde](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/7/1/71dd6b9d33994e1b1d78027c75e023a883ebd78b.png)

Habpanel

 ![bilde](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/4/a/4a363bddc506d46d5cce62bb24f2ef6b7399a96a.png)

---

<div class="post-metadata">

**Author:** ![tomhag](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@tomhag](https://community.openhab.org/u/tomhag)\
**Post date:** [October 31, 2018, 8:31pm UTC](https://community.openhab.org/t/problems-with-converting-numeric-items/55336/2 "2018-10-31T20:31:20Z")

</div>

What i thought was that the item files should be something linke this:

```csv
Number V3601Utetemp "Temperatur utetemp" <temperature> { modbus="input:23:transformation=JS(devideTemp.js)" }

```

But it does not work.

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [October 31, 2018, 8:37pm UTC](https://community.openhab.org/t/problems-with-converting-numeric-items/55336/3 "2018-10-31T20:37:57Z")

</div>

That should be about right. What does not work exactly?

---

<div class="post-metadata">

**Author:** ![tomhag](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@tomhag](https://community.openhab.org/u/tomhag)\
**Post date:** [October 31, 2018, 8:46pm UTC](https://community.openhab.org/t/problems-with-converting-numeric-items/55336/4 "2018-10-31T20:46:30Z")

</div>

> [@tomhag](#):
>
> :transformation=JS(devideTemp.js)" }

In this case it still shows the same value just that it removed the “%”.  
Was thinking that it was ignoring the :transformation=JS(devideTemp.js)" part of it

```auto

```

---

<div class="post-metadata">

**Author:** ![tomhag](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@tomhag](https://community.openhab.org/u/tomhag)\
**Post date:** [October 31, 2018, 8:46pm UTC](https://community.openhab.org/t/problems-with-converting-numeric-items/55336/5 "2018-10-31T20:46:49Z")

</div>

![bilde](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/e/f/ef6f3ea3c0e21a1bdd2efdfc6ec84805c585eaa7.png)

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [October 31, 2018, 9:42pm UTC](https://community.openhab.org/t/problems-with-converting-numeric-items/55336/6 "2018-10-31T21:42:05Z")

</div>

> [@tomhag](#):
>
> In this case it still shows the same value just that it removed the “%”.

The presentation is about what you put in the Item’s label, you took out the part telling it to display C  
Try

```csv
Number V3601Utetemp "Temperatur utetemp [%.2f °C]" ....

```

That’s where you first had your transform, it altered the display value but not the Item actual value.

Applying the transform to the modbus binding instead will work on the number _before_ it gets put into the Item,  
I would guess your transform is actually failing - should be able to see that in your log? - because the transform is trying to put a string with a comma and ‘°C’ into a purely Number Item.

You need to change your transform so it that just does the numeric part.  
The modbus binding v1 page includes an example of a divide-by-10 transform. You should be easily able to make a divide-by-100 version  
[https://www.openhab.org/addons/bindings/modbus1/#item-configuration-examples](https://www.openhab.org/addons/bindings/modbus1/#item-configuration-examples)

---

<div class="post-metadata">

**Author:** ![tomhag](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@tomhag](https://community.openhab.org/u/tomhag)\
**Post date:** [October 31, 2018, 9:54pm UTC](https://community.openhab.org/t/problems-with-converting-numeric-items/55336/7 "2018-10-31T21:54:23Z")

</div>

You were correct, also i needed to change the Modbus driver abit.  
it works with this:

```csv
Number V3601Utetemp "Temperatur utetemp [%.1f °C]" <temperature> { modbus="<[input:23:transformation=JS(devideTemp.js)]" }

```
