Forum Moderators: coopster

Message Too Old, No Replies

how to convert float number to integer?

         

hsceeus

11:13 am on Mar 20, 2006 (gmt 0)

10+ Year Member



i have a number : 23.56789

i want the number come out with 24..

how can i do it in PHP?

omoutop

11:17 am on Mar 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



to round up use ceil(), to round down use floor().

Also you can try to use (int) or (integer) to transform you float

jatar_k

5:31 pm on Mar 20, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> you can try to use (int) or (integer) to transform you float

be careful with typecasting in php, it may not work as expected, or at all, as in php you can swap types on the fly. ceil() or floor() are good bets or even plain old round().

take a look at this as well
Converting to integer [ca3.php.net]

DaSingh

11:01 am on Mar 22, 2006 (gmt 0)

10+ Year Member



You could try intval()

eg:
$val = 4.22222;
$val_int = intval($val);