This question already has answers here:
How to convert a currency string to a double with Javascript?
(23 answers)
Closed 6 years ago.
I have a string like this
"$2,099,585.43"
"$" maybe any symbol, like #,#..etc.
I want to convert this into 2099585.43
Is there any simple way to do this?
Use String#replace and remove characters which are not a digit or dot.
console.log(
"$2,099,585.43".replace(/[^\d.]/g, '')
)
Related
This question already has answers here:
How to convert a string to an integer in JavaScript
(32 answers)
Closed 1 year ago.
Convert the string "42" into a number explicitly.
I have to do this in javascript. What's the conversion
that s the problem
Use the parseInt(); function
var a = parseInt("42")
console.log(a);
This question already has answers here:
Remove commas from the string using JavaScript
(3 answers)
Closed 4 years ago.
How could I transform a number with commas like 123,245 to a number without commas like this 123245, I know that you could already put commas in number without them but how to do that in reverse?
pure JAVASCRIPT please!
var number = Number("123,456".split(",").join(""));
Or:
var number = parseInt("123,456".split(",").join(""));
An alternative is using a regex /,/g
console.log("123,245".replace(/,/g, ''));
console.log("123,245,566".replace(/,/g, ''));
This question already has answers here:
How to format numbers? [duplicate]
(17 answers)
Closed 5 years ago.
How to add commas in numbers in JavaScript ?
For example I want to add commas in this number 1445456523.56594
Use toLocaleString
var n=1445456523.56594;
console.log(n.toLocaleString());
This question already has answers here:
Strip all non-numeric characters from string in JavaScript
(12 answers)
Closed 8 years ago.
I get a number format string from an input box like: 1,033.00
How can I convert it to 1033 by jquery/javascript?
I have to use this converted number to add it with another number.
You can do a string replace numberString= numberString.replace ( /[^0-9]/g, '' );
To add it to another number you can use + operator to convert the numberString to a number value.
var numberString= numberString.replace ( /[^0-9]/g, '' );
var addition = +numberString + anotherNumber;
This question already has answers here:
How to convert a string to an integer in JavaScript
(32 answers)
Closed 8 years ago.
I am getting a numeric value from an element using
$('.myEm').text();
It returns a number from the element, but I need to increment the value by another value.How do I convert it to an integer?
Use parseInt(... ) mate.
var a = parseInt("10")
http://www.w3schools.com/jsref/jsref_parseint.asp