0

I want to convert string into number without loosing the actual value,I have tried all possible way ,couldn't solve it

const value = "324,864.88"
const value2 = '-88.88'
parseFloat(value.split(',').join(''));//this converts into integer, but loose, the value
Tony
  • 87
  • 4
  • Please actually show us what you've tried. `value2` gets parsed fine by `parseFloat` and for `value` all you need to do first is remove the comma(s) (a separate question with lots of existing answers) – ChrisG Jul 07 '21 at 09:44
  • parseFloat(yournumber.replace(/,/g, '')); see this [post](https://stackoverflow.com/q/11665884/5338672) – Hossein Jul 07 '21 at 09:45
  • WHy flag the question, that answer doesn't resolve my query, i want the comma to be added – Tony Jul 07 '21 at 09:50
  • 1
    Javascript [numbers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) don't have commas. So you can't have them *added*. What you describe is a formatting issue, when displaying numbers. Meaning, if you want to do math on them, convert them to proper numbers, if you want them to be displayed according to some format, convert them to strings. You can't have both at the same time. – Yoshi Jul 07 '21 at 09:55

0 Answers0