Answer the question
In order to leave comments, you need to log in
How to form a value of type string into number?
I am receiving data from json, and there was a problem in color rendering to three.js, in json itself you cannot write such a value as 0x000000 as this is an error, so I write it as a string, and when I receive it, I want to transfer it just to number type with this format 0x55555
Answer the question
In order to leave comments, you need to log in
All numbers in JavaScript, both integer and fractional, are of type Number and are stored in the 64-bit IEEE-754 format, also known as "double precision".
let num = 349525;
'0x' + num.toString(16); // "0x55555"
parseInt("0x55555", 16) // 349525
num.toString(2); // "1010101010101010101"
parseInt("1010101010101010101", 2) // 349525
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question