# OSC Integer Support / NodeRed Integer

**URL:** <https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810>\
**Category:** General\
**Created:** [29 April 2025 15:01 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810 "2025-04-29T15:01:37Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![borrisschwarz](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@borrisschwarz](https://discourse.nodered.org/u/borrisschwarz)\
**Post date:** [29 April 2025 15:01 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/1 "2025-04-29T15:01:37Z")

</div>

I am new to NodeRED and highly very, very exited about all the possibilities!

So here is my problem:

I want to use nodeRED to convert Ember+ messages coming from LawoVSM to OSC messages to remote a yamaha DM7, but I fail in sending osc messages from NodeRED, that contain a "integer". My system is fine regarding any meassage as "string", but whenever i insert a number it is sent as a "float".  
So i can send strings to rename a console channel but I cant change anything containing number because the OSC module is sending a "float" instead. The yamaha console needs integers for a lot of the parameters.

Is there anyone who can program a "function", so I can just copy and paste it between the insert and the OSC module? I failed with all exaples in the forum and chatGPT didnt help either.

Or is there a possibiliy to update the OSC module, so it will support integer?  
THAT would be awesome!

Thanks in advance and best regards!

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [29 April 2025 15:46 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/2 "2025-04-29T15:46:26Z")

</div>

You can round the floating point number using this code in a function node

```auto
msg.payload = Math.round(msg.payload)
return msg

```

Or alternatively, a Jsonata expression in a change node

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af47756e1618f7b7afe646e4731329354b9ee3ca.png)

Unfortunately I don't know if your Yamaha device will accept the rounded number as an integer.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 April 2025 16:05 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/3 "2025-04-29T16:05:27Z")

</div>

You can convert a number to the nearest integer string in a function node using something like  
`let strValue = someNumber.toString(0)`  
See [JavaScript toFixed() Method](https://www.w3schools.com/jsref/jsref_tofixed.asp)

---

<div class="post-metadata">

**Author:** ![JeromeVISUALS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeromevisuals/32/40103_2.png) [@JeromeVISUALS](https://discourse.nodered.org/u/JeromeVISUALS)\
**Post date:** [29 April 2025 17:58 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/4 "2025-04-29T17:58:05Z")

</div>

Hi !

Not sure exactly about your problem but happy to have a look on sample flow if you want to.

Fyi I m also in media broadcast business and mainly use NR to prototype different kind of workflows related to different media topics.

Would be happy to share some use cases and experiences with you if interested.

Jerome

---

<div class="post-metadata">

**Author:** ![borrisschwarz](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@borrisschwarz](https://discourse.nodered.org/u/borrisschwarz)\
**Post date:** [30 April 2025 06:38 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/5 "2025-04-30T06:38:07Z")

</div>

Thx for the quick, but both dont work! Both versions have a number as payload - and a number is transformed by the OSC module to a float...and yamaha does not accept that as an integer.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [30 April 2025 06:43 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/6 "2025-04-30T06:43:56Z")

</div>

What about this?

```auto
msg.payload = Math.round(msg.payload).toString()

```

---

<div class="post-metadata">

**Author:** ![borrisschwarz](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@borrisschwarz](https://discourse.nodered.org/u/borrisschwarz)\
**Post date:** [30 April 2025 06:46 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/7 "2025-04-30T06:46:44Z")

</div>

Thx for the quick answer. I tried the code and I get the error message:

"ReferenceError: ReferenceError: someNumber is not defined (line 1, col 11)"

Any Ideas what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![borrisschwarz](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@borrisschwarz](https://discourse.nodered.org/u/borrisschwarz)\
**Post date:** [30 April 2025 06:51 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/8 "2025-04-30T06:51:05Z")

</div>

Thx for the quick answer. This makes it a string and i need an integer for yamaha.

---

<div class="post-metadata">

**Author:** ![borrisschwarz](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@borrisschwarz](https://discourse.nodered.org/u/borrisschwarz)\
**Post date:** [30 April 2025 06:52 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/9 "2025-04-30T06:52:32Z")

</div>

Jerome, that would be nice! Just write a mail@ .de

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 April 2025 07:30 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/10 "2025-04-30T07:30:58Z")

</div>

> [@borrisschwarz](#):
>
> "ReferenceError: ReferenceError: someNumber is not defined (line 1, col 11)"
> 
> Any Ideas what I am doing wrong?

You were supposed to put whatever variable you number is in where I used `someNumber`. So if you number is in msg.payload then  
`let strValue = msg.payload.toString(0)`  
Did you look at the link I posted in order to understand what the code does?

---

<div class="post-metadata">

**Author:** ![JeromeVISUALS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeromevisuals/32/40103_2.png) [@JeromeVISUALS](https://discourse.nodered.org/u/JeromeVISUALS)\
**Post date:** [30 April 2025 08:59 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/11 "2025-04-30T08:59:14Z")

</div>

Hi, I just gave it a try and could see indeed that OSC node converts any number to FLOAT by default.  
You can pass an object with data type to force the node to send INT32 instead of float , have a look here :

```auto
[
    {
        "id": "3039abf1.cfc654",
        "type": "inject",
        "z": "6557ea532e17328b",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "",
        "topic": "/yamahatest",
        "payload": "{\"type\":\"i\",\"value\":12}",
        "payloadType": "json",
        "x": 470,
        "y": 500,
        "wires": [
            [
                "bf7a29be.4085d8"
            ]
        ]
    },
    {
        "id": "bf7a29be.4085d8",
        "type": "osc",
        "z": "6557ea532e17328b",
        "name": "",
        "path": "",
        "metadata": false,
        "x": 650,
        "y": 500,
        "wires": [
            [
                "fcc1e2bd.033e2"
            ]
        ]
    },
    {
        "id": "fcc1e2bd.033e2",
        "type": "udp out",
        "z": "6557ea532e17328b",
        "name": "",
        "addr": "127.0.0.1",
        "iface": "",
        "port": "3345",
        "ipv": "udp4",
        "outport": "",
        "base64": false,
        "multicast": "false",
        "x": 850,
        "y": 500,
        "wires": []
    }
]

```

Quick test in Protokol, we see the second try with the object is fine :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/58022dbc04ee7cb2caad6808a5904814ed60144f.png)

---

<div class="post-metadata">

**Author:** ![borrisschwarz](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@borrisschwarz](https://discourse.nodered.org/u/borrisschwarz)\
**Post date:** [30 April 2025 09:19 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/12 "2025-04-30T09:19:20Z")

</div>

> [@Colin](#):
>
> Did you look at the link I posted in order to understand what the code does?

Colin, thanks so much - yes I did but it seems it didnt help (i guess because i dont get it).  
I need the output to be an integer but not a string?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 April 2025 09:34 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/13 "2025-04-30T09:34:04Z")

</div>

> [@borrisschwarz](#):
>
> I need the output to be an integer but not a string?

In javascript there are only numbers and strings (and objects, booleans etc). There is no such thing as float or integer. Others have told you how to make sure that the number is a whole number, not a fractional one. It seems that your problem is specific to the OSC node, so I suggest you look at the solutions offered by those who know about that node.

---

<div class="post-metadata">

**Author:** ![borrisschwarz](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@borrisschwarz](https://discourse.nodered.org/u/borrisschwarz)\
**Post date:** [30 April 2025 09:58 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/14 "2025-04-30T09:58:22Z")

</div>

> [@JeromeVISUALS](#):
>
> Quick test in Protokol, we see the second try with the object is fine :

Jerome, thats a big step forward for me!!!  
But i need a "function" or a "change", which makes the input (finally coming from Ember+) into the integer (for the DM7)

What would the code look like for that?

---

<div class="post-metadata">

**Author:** ![JeromeVISUALS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jeromevisuals/32/40103_2.png) [@JeromeVISUALS](https://discourse.nodered.org/u/JeromeVISUALS)\
**Post date:** [30 April 2025 10:17 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/15 "2025-04-30T10:17:17Z")

</div>

As discussed by mail, but still i put it here if useful for other people, here is a quick sample code that would do the job :

```auto
[
    {
        "id": "0eae815a5e3cac4a",
        "type": "inject",
        "z": "869e1fa67fd8309e",
        "name": "Channel 1 ON",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "/yamahatest",
        "payload": "1",
        "payloadType": "num",
        "x": 350,
        "y": 220,
        "wires": [
            [
                "1c8f9e9b4b1f757f"
            ]
        ]
    },
    {
        "id": "1c8f9e9b4b1f757f",
        "type": "function",
        "z": "869e1fa67fd8309e",
        "name": "assign integer Type",
        "func": "\nlet vsmMessage = msg.payload;\nlet yamahaMessage = {};\n\n// Do stuff only if msg is integer\nif (Number.isInteger(vsmMessage)) {\n\n yamahaMessage = {\n \"type\": \"i\",\n \"value\": vsmMessage\n }\n msg.payload = yamahaMessage\n}\n// Otherwise pass msg.payload without modification\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 650,
        "y": 300,
        "wires": [
            [
                "ce830894e9682cca",
                "499f50c39198a0d6"
            ]
        ]
    },
    {
        "id": "ce830894e9682cca",
        "type": "osc",
        "z": "869e1fa67fd8309e",
        "name": "",
        "path": "",
        "metadata": false,
        "x": 850,
        "y": 300,
        "wires": [
            [
                "9ea7ea73eef103cf"
            ]
        ]
    },
    {
        "id": "b6eaf74c496a3003",
        "type": "inject",
        "z": "869e1fa67fd8309e",
        "name": "Channel 1 OFF",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "/yamahatest",
        "payload": "0",
        "payloadType": "num",
        "x": 360,
        "y": 280,
        "wires": [
            [
                "1c8f9e9b4b1f757f"
            ]
        ]
    },
    {
        "id": "bcc78b2f39b292ce",
        "type": "inject",
        "z": "869e1fa67fd8309e",
        "name": "test Float",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "/yamahatest",
        "payload": "1.25",
        "payloadType": "num",
        "x": 340,
        "y": 320,
        "wires": [
            [
                "1c8f9e9b4b1f757f"
            ]
        ]
    },
    {
        "id": "107f216a17959ddd",
        "type": "inject",
        "z": "869e1fa67fd8309e",
        "name": "test String",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "/yamahatest",
        "payload": "HelloWorld",
        "payloadType": "str",
        "x": 340,
        "y": 360,
        "wires": [
            [
                "1c8f9e9b4b1f757f"
            ]
        ]
    },
    {
        "id": "9ea7ea73eef103cf",
        "type": "udp out",
        "z": "869e1fa67fd8309e",
        "name": "",
        "addr": "127.0.0.1",
        "iface": "",
        "port": "3345",
        "ipv": "udp4",
        "outport": "",
        "base64": false,
        "multicast": "false",
        "x": 1040,
        "y": 300,
        "wires": []
    },
    {
        "id": "499f50c39198a0d6",
        "type": "debug",
        "z": "869e1fa67fd8309e",
        "name": "check Payload",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 880,
        "y": 340,
        "wires": []
    }
]

```

---

<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:** [29 July 2025 10:17 UTC](https://discourse.nodered.org/t/osc-integer-support-nodered-integer/96810/16 "2025-07-29T10:17:56Z")

</div>

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