13,045,285 members (65,387 online)
Rate this:
See more:
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 12-Jan-13 4:42am
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
Richard MacCutchan 13-Jan-13 5:13am

Well you need to use some other format command to set the converted string into the `timerTextP1` field. It's no good using `System.out.format` as that just writes to the console. I am not sure what the actual method would be in Android code.

Rate this:

## Solution 1

I'd just divide by 100 before displaying it.
Rate this:

## Solution 2

You could try something like:
```int amount;
int dollars = amount / 100;
int cents = amount % 100;
System.out.format("Amount = %d.%d", dollars, cents);```

Top Experts
Last 24hrsThis month
 OriginalGriff 263 Graeme_Grant 135 ppolymorphe 134 Atlapure Ambrish 80 kp564 70
 OriginalGriff 4,683 RickZeeland 1,854 ppolymorphe 1,708 F-ES Sitecore 1,553 Dave Kreskowiak 1,349