I have a string number like this: price = "200.000" I would like to convert this value to the number: 200.000 How can I do that? I tried to convert this value with parseInt(), but it remove number after the dot.
If you mean 200.000
represents 200 thousand, you should remove all non-decimal characters before you parseInt
by using replace
. And if you want to display in that format, use toLocaleString
to output it that way (which is de-DE
)
let numberString = '20.000.000'; let number = parseInt(numberString.replace(/[^\d]/g, '')); console.log('Your number is: ' + number); console.log('Your formated number is: ' + number.toLocaleString('de-DE'));
you should use parseFloat('200.00').toFixed(3);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.