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

1

3 Answers 3

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);

Sign up to request clarification or add additional context in comments.

Comments

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);

1 Comment

if value has 2 comma's Example (5,000,000)
0
var amount = parseInt(5000).toLocaleString('en').replace(",", "");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.