B
B
bpGusar2018-03-23 11:49:59
JavaScript
bpGusar, 2018-03-23 11:49:59

How to translate the number 1 617.78 from string into a numeric value with 2 numbers after the decimal point?

How to convert the number 1 617.78 from string to integer with 2 numbers after the comma (or dot)?

Tried like this:

parseFloat(тут число 1 617.78 которое вытягивается из атрибута data).toFixed(2)

Doesn't work, returns 1.00

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nurlan, 2018-03-23
@bpGusar

Integer is an integer. Therefore, the answer to your question is "no".
PS 1 617.78 already with two digits after the decimal point (or dot).
The code will return Although I am confused by the space in your number. PS If the problem is in the space and you have a problem with the wording, then here:

data='1 123.32245'
num=parseFloat(data.replace(' ','')).toFixed(2)
parseFloat(num)
>>1123.32

Get num as a number. If you remove the last line, you get num, as a string representation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question