Get wrong number from debug node

Hi,there

Please helped me,

I designed a simple flow as below,

timestample -> function ->debug

My function dseigined as below,

msg.payload =0x01033120000C4AF9;
return msg;

I send 0x01033120000C4AF9 (hex)

But I got the wrong number 0x01033120000C4B00 (hex) in debug node.

The code and picture as attactment

4
3



TestFlow.json (1.6 KB)

Is that larger than the maximum integer that can be held accurately in JavaScript? Google for
JavaScript maximum integer
To check.

Thank you for your reply

But my teacher can show the correct number as the same flow.

Indeed as @Colin suggests

Did he use BigInt?

image

NOTE: To clarify for future readers.

The problem is not with Node-RED or the debug panel, it is due to the design on the Number type.

See: Number.isSafeInteger() - JavaScript | MDN

How should i fix this problem?

i would send the larger number

That depends on what do you want to do with that number.

As I went to extreme lengths to demonstrate...

Use BigInt


Of course, it matters where you are sending this?

I have a device that receive hex number ,when the device receive right instruction,
it will send the state to me.
I designed the flow as the photo.

If you have any idea ,please tell me.

Thank you Steve-Mcl

I have used BigInt function in function node,but i also get wrong number.

as photo


1671430021420

You have put brackets around the number and then called toString causing the number to be evaluated before the call to bigint

Take another look at my screenshot

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