note 76007 deleted from function.round by danbrown

From: Date: Sun, 17 May 2009 16:17:58 +0000
Subject: note 76007 deleted from function.round by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154790@lists.php.net to get a copy of this message
Note Submitter: lex_63de at yahoo dot de ---- 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); }

« previous php.notes (#154790) next »