Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert currency to decimal number JavaScript

How can I convert currency string like this $123,456,78.3 to number like this 12345678.3 I tried to do using this pattern

let str = "$123,456,78.3";
let newStr = str.replace(/\D/g, '');

but it replaces . too.

like image 615
Derenik Avatar asked Oct 15 '25 17:10

Derenik


1 Answers

var str = "$123,456,78.3";
var newStr = Number(str.replace(/[^0-9.-]+/g,""));
like image 185
Heysem Avatar answered Oct 18 '25 05:10

Heysem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!