File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

number formatting

 
Viggo Oppeg�rd
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I'm new to this forum, but you guys seem helpful, so I'll give it a shot and post my question here:
Basically i have a number with two decimals (Currency format), eg 1 000 000.89 dollars that i want to format so that the two decimals are separate from the rest of the number: eg 1 000 000 dollars and 89 cents. How??
Thanks in advance
 
Jeff Bosch
Ranch Hand
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could make a new class with int dollars and int cents as data members.

(Not sure if you're looking for a storage solution or an extraction solution.)
 
Viggo Oppeg�rd
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, that's one step ahead, but I still need an extraction method...
 
Jeff Bosch
Ranch Hand
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you cast your value to an int, you have the dollars.

If you multiply your value by 100, then take modulus 100, you have your cents.

Good luck!
 
Viggo Oppeg�rd
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a heap, that worked great!
 
Jeff Bosch
Ranch Hand
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome! Glad to help.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Bosch:
If you cast your value to an int, you have the dollars.

If you multiply your value by 100, then take modulus 100, you have your cents.

Good luck!

Or you could subtract the integer dollar value from the first step and then multiply by 100.
 
Jeff Bosch
Ranch Hand
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep. One of the beautiful things about programming is that there is always another valid way to do things!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic