I Can't Get Proper Uint32 Number In Javascript
Solution 1:
That's because your number literal is rather a 64 bit integer, and that cannot be represented in JavaScripts regular Number type. The number type is a 64-bit precision floating point number, which can only represent integer values up to around 2**53
. So I would recommend to just not use such a huge number literal.
A recent development in the JavaScript world is BigInts. If you can afford to use them, then your code is easy to fix:
var t = Number(BigInt.asUintN(32, 431430059159441001n));
console.log(t); // 1570754153
Solution 2:
This is not about uints, but about floats. JavaScript uses floating point numbers, and your number exceeds the maximum range of integers that can safely be represented:
console.log(431430059159441001)
Solution 3:
You cannot convert 431430059159441001
to unsigned integer in c#. Max Value of UInt32
is 4294967295
. So the var t=(UInt32)431430059159441001;
assignment gives Compiler error.
also 431430059159441001
is larger then max value of float number (javascript holds number with float format)
Post a Comment for "I Can't Get Proper Uint32 Number In Javascript"