Forum Moderators: coopster

Message Too Old, No Replies

Rounding a random number

         

dkin

10:04 am on Jan 16, 2005 (gmt 0)

10+ Year Member



I am returning random numbers such as this

172.66666666667
191.66666666667
176.66666666667
184.66666666667

they all have .66666666667 and I do not wish to have any decimal places, how can I get rid of this?

eaden

10:22 am on Jan 16, 2005 (gmt 0)

10+ Year Member



you can use the function round().

dkin

10:32 am on Jan 16, 2005 (gmt 0)

10+ Year Member



IU have tried that, I keep getting errors, cant seem to get it working.

dkin

10:40 am on Jan 16, 2005 (gmt 0)

10+ Year Member



I figured it out, just needed to tamper with it.

dreamcatcher

10:56 am on Jan 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



or try number_format.

$string = "172.66666666667";

echo number_format($string, 0);

The 0 denotes decimal places. In this example, $string would be = to 172

Hope that helps.

dc