Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# number formatting

Viggo Oppeg�rd
Greenhorn
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??

Jeff Bosch
Ranch Hand
Posts: 805
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
thanks, that's one step ahead, but I still need an extraction method...

Jeff Bosch
Ranch Hand
Posts: 805
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
thanks a heap, that worked great!

Jeff Bosch
Ranch Hand
Posts: 805

Layne Lund
Ranch Hand
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.

Jeff Bosch
Ranch Hand
Posts: 805
Yep. One of the beautiful things about programming is that there is always another valid way to do things!