Re: Need unrounded precision
| From: | Philip Thompson | Date: | Wed, 14 Oct 2009 19:52:46 +0000 |
| Subject: | Re: Need unrounded precision | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298895@lists.php.net to get a copy of this message | ||
On Oct 12, 2009, at 2:37 PM, Andrea Giammarchi wrote:
bitwise right shift is probably the fastest cast to int so far ... still in many languages, intval is a function call being a cast in both cases (int) is good as well ... bitwise, casting, works with strings, arrays, boolean, whatever as well. I don't think there is any difference in php, except when the integer is "too big" ... but this was not the case, we had to deal with 1 to 10 :-) RegardsI like the bitwise shifting, but here's another potential (albeit probably slower) solution. $a = 28.56018; list (,$dec) = explode ('.', $a); $b = $dec{0}; Cheers, ~PhilipFrom: jbozza@mindsites.com To: an_red@hotmail.com CC: php-general@lists.php.net Date: Mon, 12 Oct 2009 11:33:10 -0500 Subject: RE: [PHP] Need unrounded precisionGood to know. In that case, I would probably just use intval() instead of >> since it's clearer and bitwise shifts aren't necessarily integer only either. JaimeHmmm... Didn't think about this, but % only works with int valuesit was just future prof precaution since this statement is false for many other languages. In few words I am not sure PHP6 does the same ... never mind so far