Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
ShowAll Questionssorted byDate Posted
Mak One

# To convert String to number according to locale (opposite of .toLocaleString)

I am getting numbers in respective language in Visualforce page from controller. Now I have to do fast calculations using those numbers. I am using javascript for that. Now, the problem is ho to read those numbers if user changes it. Suppose it is in Hindi.3500 will be displayed as ३,५०० and user can change it to ३,५५५ (3555). So what can I use to convert ३,५५५ to 3555.

If I do:

var number = 3500;
I will get ३,५०० in Hindi.

But how can I convert it back to 3500. I want something like:

var str='३,५००';
So, that it can give 3500.

Is it possible by javascript, jquery or any other free or paid library?

I tried jquery.numberformatter which is not working for this.
Gaurav Nirwal
You can try this command to solves it

var number = 3500;
I will get ३,५०० in Hindi.
Gaurav Nirwal
For changing it in english you can try this

var str='३,५००';
So, that it can give 3500.

Vatsal Kothari
Hi Mak,

You can do this by creatinf your own function.
You can refer below code:

```var str = '३,५००';
var engNum = '';
for (i = 0; i < str.length; i++) {
if(str.charAt(i) == '१'){
engNum += '1';
}else if(str.charAt(i) == '२'){
engNum += '2';
}else if(str.charAt(i) == '३'){
engNum += '3';
}else if(str.charAt(i) == '४'){
engNum += '4';
}else if(str.charAt(i) == '५'){
engNum += '5';
}else if(str.charAt(i) == '६'){
engNum += '6';
}else if(str.charAt(i) == '७'){
engNum += '7';
}else if(str.charAt(i) == '८'){
engNum += '8';
}else if(str.charAt(i) == '९'){
engNum += '9';
}else if(str.charAt(i) == '०'){
engNum += '0';
}
}