aspose file tools*
The moose likes Java in General and the fly likes Big Decimal Currency Formatting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Big Decimal Currency Formatting" Watch "Big Decimal Currency Formatting" New topic
Author

Big Decimal Currency Formatting

Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
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


SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40029
    
  28
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

Joined: Oct 27, 2005
Posts: 19781
    
  20

Campbell is probably right. Check the development machine for its currency symbol. Perhaps it is � or €.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
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

Joined: Oct 13, 2005
Posts: 40029
    
  28
You're welcome
Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

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.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
Thanks Martijn, I will keep that in mind
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Big Decimal Currency Formatting