note 82412 added to function.round

From: Date: Wed, 09 Apr 2008 21:04:10 +0000
Subject: note 82412 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-138078@lists.php.net to get a copy of this message
Regarding the change of behavior where round now returns certain values in exponential notation, here's a third way this can bite you (see previous Notes below for ways one and two). Say you have to this code to build a stored procedure call. If you pass round() one of the "special values", e.g., '1200000', and you get a return value in exponential notation, e.g., '1.2E+6', you will likely have a mismatch of types between the resulting value in the procedure call (a string) and the database column definition (likely a decimal for monetary values), yielding yet another failed transaction: <? // assume $totalDebt contains 1200000 $sql = "exec update_loan_financials @application_id='$appID', @total_debt=" . round($totalDebt); // string '1.2E+6' ?> If it matters, a poster on the PHP General mail list said that this new behavior is actually a property of the float type, in general, not the round function, in particular. Replace your round() call with a cast to float and you'll see the exact same result. It doesn't matter to me, I just know my code is breaking. ---- Server IP: 64.71.164.2 Probable Submitter: 12.7.177.130 ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/82412 Del: integrated -- https://master.php.net/note/delete/82412/integrated Del: useless -- https://master.php.net/note/delete/82412/useless Del: bad code -- https://master.php.net/note/delete/82412/bad+code Del: spam -- https://master.php.net/note/delete/82412/spam Del: non-english -- https://master.php.net/note/delete/82412/non-english Del: in docs -- https://master.php.net/note/delete/82412/in+docs Del: other reasons-- https://master.php.net/note/delete/82412 Reject -- https://master.php.net/note/reject/82412 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138078) next »