Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert String to Number according to locale (opposite of .toLocaleString)?

Tags:

javascript

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 library?

like image 457
user2754545 Avatar asked Sep 03 '14 13:09

user2754545


People also ask

How do I convert a string to a number in node?

You can convert a string to a number in Node. js using any of these three methods: Number() , parseInt() , or parseFloat() .

What is the use of toLocaleString () method?

The toLocaleString() method returns a Date object as a string, using locale settings. The default language depends on the locale setup on your computer.

Which function in Javassript converts a number to a string?

The toString() method is a built-in method of the JavaScript Number object that allows you to convert any number type value into its string type representation.


1 Answers

I think you are looking for something like:

https://github.com/jquery/globalize

Above link will take you to git project page. This is a js library contributed by Microsoft. You should give it one try and try to use formt method of that plugin. If you want to study this plugin, here is the link for the same:

http://weblogs.asp.net/scottgu/jquery-globalization-plugin-from-microsoft

I hope this is what you are looking for and will resolve your problem soon. If it doesn't work, let me know.

like image 175
Priyank Sheth Avatar answered Sep 28 '22 00:09

Priyank Sheth