function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
fadwa mangougfadwa mangoug 

How to replace commas and dots in numbers ?

Hey there !

I'm having trouble converting numbers from US Format to Europe Format.
I want to convert someting like : 1,000,000.555 to 1000000,555 
So in an VF Page I have a script and tried this for now doesnt seem to work for the decimal  part and i just convert the comma part for thousands :

value = 1,000,000.555
var regex = new RegExp(',', 'g');
value = parseFloat(value.replace(regex,'').replace(/\./g, ','));


the first replace works but not the second one 

I would really appreciate some help !

Thanks in advance !

Fadwa.
Nayana KNayana K
value = '1,000,000.555';
var regex = new RegExp(',', 'g');
value = parseFloat(value.replace(regex,'').replace(/\./g, ','));

Since value.replace(regex,'').replace(/\./g, ',') gives '1000000,555' , parseFloat on this value will return 1000000 


If you want final value from 1000000,555 to 1000000555 then,

var value = '1,000,000.555';
var regex = new RegExp(',', 'g');
value = parseFloat(value.replace(regex,'').replace(/\./g, ',').replace(regex,''));
fadwa mangougfadwa mangoug
Thanks a lot for the quick answers, it actually works much better now !
 
Nayana KNayana K
Please mark this as solved