G
G
GayLord632019-01-15 12:59:48
JavaScript
GayLord63, 2019-01-15 12:59:48

How to make from string number in node.js?

Hello. How to convert string to number? For some reason the Number(...) function doesn't work. Well, for example, there is a string "222". I need to get this number 222 and write it to a variable.
Well, it doesn't work. Gives out NaN

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shmatuan, 2019-01-15
@shmatuan

parseFloat("222") // 222
parseFloat("222.2") // 222.2

//есть parseInt, но 
parseInt("222") //222 
parseInt("222.2") //222

A
Abcdefgk, 2019-01-15
@Abcdefgk

exotic variant

var n = +'222';
console.log(typeof n); // number

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question