• Post Reply Bookmark Topic Watch Topic
  • New Topic

DecimalFormat is not setting the format for is_IS Language  RSS feed

 
prafull kherde
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Do any buddy have idea about the applyLocalizedPattern(fmt) method from class DecimalFormat.
My problem is when I am setting the format for en_US it is setting the format (ex: $#0.00 for USD) properly but the same is not working for is_IS language code.
like for en_US if money is $21.0 then it is formatted to $21.00
This is ok
But for is_IS if money is $21.0 then it is formatted to $0.21

I am using the same format for both and I had tried with other format but I am not getting the expected results like en_US language.

What may the problem?

If this information is insufficient then just let me know.


Thanks
Prafull
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I have 21,00 for is_IS. Can you post your code so we can see why you're getting 0.21 ?
 
prafull kherde
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satou,

Hear is my code





It is taking the money as 21.0 but when it apply the format then it changes to 0.21

Expression I have caught in eclipse are as below

New Double(money)=21.0 this is ok

But format.format(new Double(money))=0.21

The format I am using is "$#0.00" for both is_IS and en_US.

If you need more details just post it ok.

Thanks
Prafull

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is with applyLocalizedPattern. It should be applyPattern instead. applyLocalizedPattern's API says that the pattern is assumed to be in a localized notation. You are using a common format for all locales. So, applyPattern should be used instead. Your Format instance already knows which locale it is using.
 
prafull kherde
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again Satou,

As you suggested I have change the method from applyLocalizedPattern to applyPattern i am giving the same pattern but now the problem is it is applying the format as below

21.0 to 21,00 for is_IS

21.0 to 21.00 for en_US

coma in is_IS is my problem.

What may be the problem?

And if I do not want to change the code how can i give the pattern in localized notation that is is_IS.

Thanks
Prafull
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a problem. I think that the comma is the decimal separator for this locale (Iceland). So 21.00 is actually 21,00 in Iceland. You could use DecimalFormat#setDecimalFormatSymbols to override this, but it's not cool. Locales are made to have predefined settings.
 
prafull kherde
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Satou. It is working ok.

I have more doubt about strut validation can I ask you.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, I'm not in Struts Try your luck at the Struts forum.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!