I'm converting a .net app to php. What would be the php equivalent of int(6.22555445656) in php?
views:
88answers:
3
+1
A:
This should clear it up:
<?php
header("Content-Type: text/plain");
$arr = array(-6, -6.2, -6.7, 5, 5.3, 5.8);
foreach ($arr as $v) {
printf("%f: (int) = %d, floor = %d, ceil = %d\n", $v, (int)$v, floor($v), ceil($v));
}
?>
outputs:
-6.000000: (int) = -6, floor = -6, ceil = -6
-6.200000: (int) = -6, floor = -7, ceil = -6
-6.700000: (int) = -6, floor = -7, ceil = -6
5.000000: (int) = 5, floor = 5, ceil = 5
5.300000: (int) = 5, floor = 5, ceil = 6
5.800000: (int) = 5, floor = 5, ceil = 6
Note: Casting to int and floor() do different things.
Edit: Oh, you want to convert from a string to an int. One piece of advice: when you ask questions like these, describe what the original function does. You'll get a quicker and clearer answer.
Also, bear in mind that types in PHP and .Net work different. For example:
$foo = '-234'; // string
$bar = $foo + 5;
print $bar; // -229
PHP has a complex type juggling system to automatically convert the type of variables as required. This includes going to and from booleans, integers, floats and strings as required.
cletus
2009-10-21 16:36:45
the interval() function was what I was looking for. Thank you!
shaiss
2009-10-21 16:44:14
I'm confused--do you mean intval() is what you were looking for?
mgroves
2009-10-21 19:30:50