Skip to content
Advertisement

How to convert a number with comma as string into float number in Javascript

Im using the parseFloat method to convert a string to a float. it works fine however when the number exceed thousand it one return the value in the thousand place.

So parseFloat('1,022.55') returns 1 instead of 1022.55 How do i solve this?

Advertisement

Answer

Try:

parseFloat('1,022.55'.replace(/,/g, ''))
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement