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
Mak OneMak 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;
alert(number.toLocaleString("hi-IN"));
I will get ३,५०० in Hindi.

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

var str='३,५००';
alert(str.toLocaleNumber("en-US"));
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 NirwalGaurav Nirwal
You can try this command to solves it 

var number = 3500;
alert(number.toLocaleString("hi-IN"));
I will get ३,५०० in Hindi.
Gaurav NirwalGaurav Nirwal
For changing it in english you can try this 

var str='३,५००';
alert(str.toLocaleNumber("en-US"));
So, that it can give 3500.

If your problem can solved please select my answer as best answer 
Vatsal KothariVatsal 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';
    }
}
alert(engNum);

If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal
Mak OneMak One
Matthews, There is no method like toLocaleNumber.
Mak OneMak One
My page have to support all locales. So, I will have to convert numbers from any locale to any other locale. Not just from hindi to english. :(