E
E
Eduard072018-12-23 17:40:03
JavaScript
Eduard07, 2018-12-23 17:40:03

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

2 answer(s)
R
RAX7, 2018-12-23
@Eduard07

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".

from here https://learn.javascript.ru/number
Writing a number as '0x55555' does not mean that the number is stored in hexadecimal system.
let num = 349525;
'0x' + num.toString(16); // "0x55555"
parseInt("0x55555", 16) // 349525

num.toString(2); // "1010101010101010101"
parseInt("1010101010101010101", 2) // 349525

P
Paul Steelway, 2018-12-23
@Steelway

Use the number() function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question