Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Big Decimal Currency Formatting

 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringBuffer strBuffer = new StringBuffer();

NumberFormat currency = NumberFormat.getCurrencyInstance();

strBuffer.append(currency.format(transaction.getBigDecimalTypeAmount()));

response.getOutputStream().write(strBuffer.toString().getBytes());
________________________________________________________________________

Here am expecting an output like $15.00, it is working fine in local environment, but after the code is pushed to development its showing ?15.00

In the NumberFormat API I dont see any format function with arguments of type BigDecimal. Is this the issue, but again it works fine in my local. Both, my local and dev environment are using java 1.4.

I could not find a good explanation in google, any suggestions are welcome. Thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is always worth checking the environment you are printing on. Some command-line windows have difficulty with currency symbols. If you take it away from a country where they use dollars, and print a different symbol, maybe the command-line window can't print and you get ? or a little box.

If you have a short String, try splitting it into chars with the toCharArray method, then print out the numbers (preferably with the %x formatting tag, not available in Java 1.4), then use the Unicode website to work out whether any of the chars corresponds to a currency symbol in the Unicode chart.
 
Rob Spoor
Sheriff
Pie
Posts: 20533
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell is probably right. Check the development machine for its currency symbol. Perhaps it is � or €.
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Campbell and Rob for your prompt replies. I just wanted to make sure if its really an environmental issue. Also the Unicode chart helps, I will definitely play with it in java. Thanks again.
[ November 11, 2008: Message edited by: Himalay Majumdar ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just after a day I posted the formatting question, another build took place in development and surprisingly the development environment is now showing $15.00 and NOT ?15.00.

How is it possible for the same command line window to print it again. Is it possble for the defect to reappear.

I have a work around for this, but just trying to understand things clearly.

Thanks
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be a case that a different command shell might have been used to run the build, depending on who that shell was opened under etc etc it can change.
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Martijn, I will keep that in mind
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic