Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

formatting amount  RSS feed

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a number like 120000,I am trying to format it like 1200.00.
I am using this function,but I am getting the result as 1,200.00.Can someone
please tell me what changes I have to make to get the desired results.Thanking you in
advance
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try just using the DecimalFormat passing your own Format String instead of relying on the Local Based Currency Format
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want a class that I created to return a currency format i.e. (30.00 just two decimals at the end for cents) I have the print statement put the $ and dollars at the end.. The problem I am running into is using the below code suggested in this thread. My value is a double how to I convert it to a string? And is there anything in the main program I have to change since I will be passing back a string instead of a double?






Thanks,

Pete
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know the formatting answer, but I'll chime in with this: Using doubles for money will make you unhappy in the long run. The rounding and truncation will not be what you expect. A decimal class or longs that keep the value in pennies (ie $1.00 == 100) are probably better choices.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Pete Tyo:
I want a class that I created to return a currency format i.e. (30.00 just two decimals at the end for cents) I have the print statement put the $ and dollars at the end.. The problem I am running into is using the below code suggested in this thread. My value is a double how to I convert it to a string? And is there anything in the main program I have to change since I will be passing back a string instead of a double?



Instead of using DecimalFormat(), you could use String.format(), something like this:

It's a bit of a shortcut, but it would leave myValue untouched for further use, and still produce the desired output format.
 
Pete Tyo
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
appreciate all the suggestions... Finally used the below code to get my desired output from a double...



Thanks,

Pete
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!