note 86708 added to function.round

From: Date: Thu, 30 Oct 2008 22:36:44 +0000
Subject: note 86708 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-145982@lists.php.net to get a copy of this message
Here's a quick gotcha: I was fetching some data from a web service using cURL & SimpleXML and getting values like 28.75. I was then rounding these values but getting 28 instead of 29. Turns out the values were strings, so round() would treat them as integers, and casting to an int drops off the decimals (like floor()). So I had to do: round( (double) $val ); HTH! ---- Server IP: 64.71.164.2 Probable Submitter: 98.221.124.112 ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/86708 Del: integrated -- https://master.php.net/note/delete/86708/integrated Del: useless -- https://master.php.net/note/delete/86708/useless Del: bad code -- https://master.php.net/note/delete/86708/bad+code Del: spam -- https://master.php.net/note/delete/86708/spam Del: non-english -- https://master.php.net/note/delete/86708/non-english Del: in docs -- https://master.php.net/note/delete/86708/in+docs Del: other reasons-- https://master.php.net/note/delete/86708 Reject -- https://master.php.net/note/reject/86708 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#145982) next »