# Convert number to array of numbers

**URL:** <https://discourse.nodered.org/t/convert-number-to-array-of-numbers/90571>\
**Category:** General\
**Created:** [30 August 2024 22:33 UTC](https://discourse.nodered.org/t/convert-number-to-array-of-numbers/90571 "2024-08-30T22:33:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eerke2021](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eerke2021/32/83528_2.png) [@eerke2021](https://discourse.nodered.org/u/eerke2021)\
**Post date:** [30 August 2024 22:33 UTC](https://discourse.nodered.org/t/convert-number-to-array-of-numbers/90571/1 "2024-08-30T22:33:36Z")

</div>

Hi, I currently have a msg.payload that is a number, for example 51.571372, which is a latitude from a GNSS device (GPS and Glonass etc), which jumps around a lot, being to 6 decimal places, the last of which is less than a meter I think.  
I thought I’d use Node Red Contrib Calc to reduce the number of decimal places but instead of one number I think it wants an array: eg.  
51.571372, 3  
Where 3 is just how many decimal places I want. In the setup of the node is a selector of how many decimal places to output. I’m tempted to just select average and 3 in the setup node, but is there a simple way to turn a number into an array of numbers? Maybe a change node where I set msg.payload to the value of msg.payload, 3? Or a template? There must be a simple way to do this I have not found.

---

<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 August 2024 22:43 UTC](https://discourse.nodered.org/t/convert-number-to-array-of-numbers/90571/2 "2024-08-30T22:43:00Z")

</div>

Not sure what you mean by an array of numbers but you can round it to 3 decimal places with Jsonata in a change node:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/50caa64996eee5ece95b40ee72490f55943dc449.png)

---

<div class="post-metadata">

**Author:** ![eerke2021](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eerke2021/32/83528_2.png) [@eerke2021](https://discourse.nodered.org/u/eerke2021)\
**Post date:** [30 August 2024 23:02 UTC](https://discourse.nodered.org/t/convert-number-to-array-of-numbers/90571/3 "2024-08-30T23:02:14Z")

</div>

Thanks. I only meant array as in the standard programming way. I have installed that node instead of a calculator node.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [31 August 2024 05:57 UTC](https://discourse.nodered.org/t/convert-number-to-array-of-numbers/90571/4 "2024-08-31T05:57:38Z")

</div>

> [@eerke2021](#):
>
> There must be a simple way to do this I have not found.

maynot be simple, but this should give what you are expecting.

```auto
[{"id":"44d8a26c4d7f3def","type":"inject","z":"4cde86148e5b95f7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":1950,"wires":[["966059502bae2ddf"]]},{"id":"bd0d75b2b7019e7f","type":"inject","z":"4cde86148e5b95f7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"3","payloadType":"num","x":425,"y":2025,"wires":[["966059502bae2ddf"]]},{"id":"966059502bae2ddf","type":"join","z":"4cde86148e5b95f7","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":625,"y":2000,"wires":[["1284b4c3cd741f8c"]]},{"id":"1284b4c3cd741f8c","type":"debug","z":"4cde86148e5b95f7","name":"debug 2670","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":780,"y":2000,"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 November 2024 05:58 UTC](https://discourse.nodered.org/t/convert-number-to-array-of-numbers/90571/5 "2024-11-29T05:58:32Z")

</div>

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