Value exceeds the limit when its converted from string to json

Hello,

I am getting a value from a robot (738775312330130003) but when I am converting into object I am getting the value(738775312330130000) with last two numbers as zero zero always.

I assume that its because the value is too big. Is there any way to solve it?

In the picture attached- the first output is the value from machine and the second one is when I convert into object.
image

                                or

What I really want is to extract only the number out from string. What are the possibilities to do it.

Yes it is too big to be held as a number. See What is JavaScript’s highest integer value that a Number can go to without losing precision.

Do you actually need it as a number or would it be ok as a string? What do you want to do with it?

If you need it as a number then you will have to use bigint, though I have never used that myself.

Here is one example

[{"id":"474599d714e96bb9","type":"inject","z":"1d319bc3005a51a2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"status\":\"success\",\"id\":738775312330130003}","payloadType":"str","x":130,"y":280,"wires":[["4aaf250378451bf5"]]},{"id":"4aaf250378451bf5","type":"change","z":"1d319bc3005a51a2","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"(\\d+)","fromt":"re","to":"\"$1\"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":280,"wires":[["c33018984742b722"]]},{"id":"c33018984742b722","type":"json","z":"1d319bc3005a51a2","name":"","property":"payload","action":"","pretty":false,"x":370,"y":360,"wires":[["d6dd91cb9c20681f","3b64295684b6c8c2"]]},{"id":"d6dd91cb9c20681f","type":"function","z":"1d319bc3005a51a2","name":"function 29","func":"msg.payload.id = BigInt(msg.payload.id);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":360,"wires":[["3b64295684b6c8c2"]]},{"id":"3b64295684b6c8c2","type":"debug","z":"1d319bc3005a51a2","name":"debug 4 flow 3","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":280,"wires":[]}]

Hello,

I just want to get the number out from the string.
image

You can't because it is too big to be held in a normal number. What do you want to do with it after you have got it out?

Thanks a lot Colin.

I just wanted to display the the string as an ID in UI.

BR

Do you have control of what the robot sends? If so then change it to send a string instead of a number.

To clarify that, can you make the robot return something like
"{"status":"success","id":"738...003"}"

How are you getting the data from the robot? Is it really coming in as JSON or are you processing the incoming data to that?

Hi,

The robot is sending data in a JSON format.

You marked an earlier post as the solution. Does that mean you have it is working ok now?

Hi,

Yes its working. Thanks a lot

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