11,932,103 members (53,442 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 5: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);
```

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

Top Experts
Last 24hrsThis month
 George Jonsson 245 BillWoodruff 230 Richard MacCutchan 144 Sergey Alexandrovich Kryukov 120 RyanDev 120
 OriginalGriff 7,926 KrunalRohit 4,930 Sergey Alexandrovich Kryukov 3,805 George Jonsson 3,305 ppolymorphe 2,406

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 12 Jan 2013