skip to Main Content

I have the following string ‘1 234’ and I would like to parse it to float.

I have tried varios of solutions but none of them works for me.

I have tried:

parseFloat('1 234'.trim())
parseFloat('1 234'.split(' ').join())
parseFloat('1 234'.replace(/ /g, ''))

2

Answers


  1. This should do it:

    > parseFloat('1 234'.replace(/s/g,''))
    1234
    >
    
    Login or Signup to reply.
  2. Maybe you can try this:

    parseFloat("1 234".replace(" ", "."))
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search