Click here to Skip to main content
15,886,734 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi there,
I have a whole number counting up and I would like to put a decimal in it to make it look like a US Dollar amount counting up. so the number 59 would be .59 and the number 259 would be 2.59.

I tried using the decimal method like this (00.##) but that just adds to 0's on the end of the number like this, 59 would be 59.00.

Any help would be awesome!

Thank you
Posted
Comments
Justin Jones 12-Jan-13 11:32am    
I tried this
float pump1time = Math.abs(timerTextP1 / 100);
timerTextP1Pump1.setText(pump1time + "");

and it looks like its trying to work but it shows 0.0 till the count up equals 1 then it shows 1.0.
it won't show the decimal as it counts up. Weird.
sarathsprakash 12-Jan-13 11:36am    
do you only want to have the two digits to be followed after the precision
like if it is 25678 then it should be 256.78 or 25.678
Justin Jones 12-Jan-13 11:56am    
only 2 digits after decimal like a US dollar amount.
25678 would be 256.78
thank you
Richard MacCutchan 12-Jan-13 12:36pm    
See my suggestion below.
Justin Jones 12-Jan-13 23:01pm    
I tried your way, but it changes nothing.

private int timerTextP1;
private int dollars = timerTextP1 / 100;
private int cents = timerTextP1 % 100;

System.out.format("timerTextP1 = %d.%d", dollars, cents);
timerTextP1Pump1.setText(timerTextP1 + "");

am I doing that right? it just displays the number normal

I'd just divide by 100 before displaying it.
 
Share this answer
 
You could try something like:
Java
int amount;
int dollars = amount / 100;
int cents = amount % 100;
System.out.format("Amount = %d.%d", dollars, cents);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900