How to convert currency string to floating point number using Javascript
P粉593118425
P粉593118425 2023-08-23 22:49:40
0
2
605
<p>I have a textbox that will have a <em>currency</em> string in it and I need to convert that string to a double precision float to perform some operations. </p> <p><code>"$1,100.00"</code> → <code>1100.00</code></p> <p>This needs to be done on the client side. I have no choice but to keep the <em>Currency</em> string as input, but need to cast it to a double precision float for some math operations. </p>
P粉593118425
P粉593118425

reply all(2)
P粉080643975

accounting.js is a good choice. I'm using it on a project and had a very good experience using it.

accounting.formatMoney(4999.99, "€", 2, ".", ","); // €4.999,99
accounting.unformat("€ 1.000.000,00", ","); // 1000000

You can find it on GitHub.

P粉208469050

Remove all non-decimal points/digits:

var currency = "-,400.50";
var number = Number(currency.replace(/[^0-9.-]+/g,""));
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!