View Single Post
Old 01-02-2007, 04:41 PM   #3 (permalink)
Nikkon
 
Super Techie

Join Date: Jul 2004

Posts: 375

Nikkon

Default

The float class has a toString() function that will convert a float to a string. From there just parse the string so that it looks like a dollar amount.

If the parsing is giving you troble heres some simple psudo code for it:

String dollars = input.length - 2;
int loop = dollars / 3;
int stringPOS = 0;

System.out.print("$");
for ( int i = 0; i < loop; i++ ) {
for (int j=0; j< 3; j++ ) {
System.out.print(input[stringPOS];
stringPOS++;
}
System.out.print(",");
}
System.out.print("." + input[input.length-2] + input[input.length-1]);

(something like that. I suck writing code without a complier).

Java Bible ->
http://java.sun.com/j2se/1.3/docs/api/
__________________
AMD 3800+ X2
Zalman CNPS7000B CPU Heatsink/Fan
ASUS A8N Premium
2 GB G. Skill DDR 400 (2 X 1 GB)
1 GB Ultra DDR 400 (2 X 512 GB)
eVGA 7800GT 256MB
120 GB seagate HD (7200RPM)
80 GB Seagate HD (7200RPM)
Sound Blaster Audigy 2 Platium ZS Sound Card
Logitec z5300 5.1 THX certified speaker
Medusa 5.1 Headphones
ATI TV turner card
DVD Drive
CD Burner Drive
Razer Copperhead Gaming mouse
Nikkon is offline