note 76007 added to function.round

From: Date: Tue, 26 Jun 2007 13:33:59 +0000
Subject: note 76007 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-127988@lists.php.net to get a copy of this message
Here is my little round function. Works nice on php 4.3.11 and 5.0.5 printf("0.285 - %s <br> ",round(0.285,2)); // incorrect result 0.28 printf("1.285 - %s <br> ",round(1.285,2)); // correct result 1.29 printf("1.255 - %s <br><br>",round(1.255,2)); // incorrect result 1.25 printf("0.285 - %s <br> ",myRound(0.285,2)); // incorrect result 0.29 printf("1.285 - %s <br> ",myRound(1.285,2)); // incorrect result 1.29 printf("1.255 - %s <br> ",myRound(1.255,2)); // incorrect result 1.255 function myRound($value,$round=2) { $value *= pow(10.0,$round); $value = floor(floatval($value + 0.6)); $value /= pow(10.0,$round); return($value); } ---- Server IP: 217.160.72.57 Probable Submitter: 195.227.4.131 ---- Manual Page -- http://www.php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/76007 Del: integrated -- https://master.php.net/note/delete/76007/integrated Del: useless -- https://master.php.net/note/delete/76007/useless Del: bad code -- https://master.php.net/note/delete/76007/bad+code Del: spam -- https://master.php.net/note/delete/76007/spam Del: non-english -- https://master.php.net/note/delete/76007/non-english Del: in docs -- https://master.php.net/note/delete/76007/in+docs Del: other reasons-- https://master.php.net/note/delete/76007 Reject -- https://master.php.net/note/reject/76007 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127988) next »