Archana Mundaye
Archana Mundaye

Reputation: 533

Localizing numeric values in excel

BigDecimal myNumber = new BigDecimal(1234.56);
NumberFormat instance = NumberFormat.getInstance(Locale.GERMAN);
String localizedNumber = instance.format(myNumber);
System.out.print("\nformatting " + localizedNumber); o/p ->1.234,56

Till here code works fine but below line gives NumberFormatter exception as given string contains comma in it.

BigDecimal bigDecimal = new BigDecimal(localizedNumber);

I want numeric values to be localized but I cannot return string as putting number as string shows below error in excel Number in this cell is formatter as text or preceded by an apostrophe

Is there any way by which I can return back numeric value(BigDecimal / Integer / BigInteger etc) in localized format So that I won't get above error in excel and I can perform filter operations on excel data.

I've also tried new BigDecimalType().valueToString(value, locale); and new BigDecimalType().stringToValue(s, locale); of dynamic jasper reports api.

Upvotes: 0

Views: 295

Answers (1)

Archana Mundaye
Archana Mundaye

Reputation: 533

Happy to answer this question which asked me only and quite surprised that no one replied to this. Actually we don't have to do anything for number localization in excel export because it's done by our operating system settings automatically.

Go to "Region and Language" -> Format -> Select language/country name -> Apply and check your excel earlier generated in English.

You will see numbers in currently selected country's number format. :)

Upvotes: 2

Related Questions