Parse number String of other languages

You can not directly parse number String of language other then English in Java. To parse number String of other language say Hindi you can use following way,

NumberFormat numberFormat = NumberFormat.getInstance(new Locale("hi", "IN"));
try {
    Number number = numberFormat.parse("३५");
    System.out.println(number.intValue());
} catch (ParseException e) {
    e.printStackTrace();
}

If you use above block of code it will print 35 in console.

You can only parse the number for one of the supported locales of Java.

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s