0

I formatted number with JavaScript toLocaleString('en') and now i want to revert the value without comma. Is there any function in JavaScript.

Example

var amount = parseInt(5000).toLocaleString('en');
console.log("amount:", amount);

result:

'5,000'

how to revert '5,000' into '5000' using JavaScript

Ali Esmailpor
  • 1,209
  • 3
  • 11
  • 22
  • Does this answer your question? [How can I parse a string with a comma thousand separator to a number?](https://stackoverflow.com/questions/11665884/how-can-i-parse-a-string-with-a-comma-thousand-separator-to-a-number) – lissettdm Jan 22 '21 at 13:03

3 Answers3

1

You need to remove , from the string using replaceAll() method.

var amount = parseInt(500000000).toLocaleString('en');
console.log(amount);


// Reverting ,
amount = amount.replaceAll(',', '');
console.log(amount);
BadPiggie
  • 5,471
  • 1
  • 14
  • 28
1

I think would be better to keep two separate variables, one for calculation purpose and one for visualization purpose:

var amount = parseInt(5000)

var amountPrint = amount.toLocaleString('en');
console.log("amount for view:", amountPrint);
console.log("amount:", amount);
Greedo
  • 3,438
  • 1
  • 13
  • 28
0
var amount = parseInt(5000).toLocaleString('en').replace(",", "");
umadik
  • 101
  • 2
  • 17