aspose file tools*
The moose likes Beginning Java and the fly likes number formatting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "number formatting" Watch "number formatting" New topic
Author

number formatting

Viggo Oppeg�rd
Greenhorn

Joined: Oct 06, 2004
Posts: 3
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

Joined: Jul 30, 2003
Posts: 804
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.)


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Viggo Oppeg�rd
Greenhorn

Joined: Oct 06, 2004
Posts: 3
thanks, that's one step ahead, but I still need an extraction method...
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
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

Joined: Oct 06, 2004
Posts: 3
thanks a heap, that worked great!
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
You're welcome! Glad to help.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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.


Java API Documentation
The Java Tutorial
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
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
 
subject: number formatting