note 24182 modified in language.types.float by jmcastagnetto

From: Date: Thu, 08 Aug 2002 23:10:58 +0000
Subject: note 24182 modified in language.types.float by jmcastagnetto
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-34580@lists.php.net to get a copy of this message
[Editor's note: the contributor did not see number_format(), sprintf() and other similar functions that can accomplish this task.] I'm sure there is an easier way to float a number to a desired precision, but I couldn't find one. So, here is a function that floats 1 decimal place. function float1($val) { $x = intval(10*$val)/10; if ($x == intval($x)) return "".$x.".0"; else return intval(10*$val)/10; } --was-- I'm sure there is an easier way to float a number to a desired precision, but I couldn't find one. So, here is a function that floats 1 decimal place. function float1($val) { $x = intval(10*$val)/10; if ($x == intval($x)) return "".$x.".0"; else return intval(10*$val)/10; } http://www.php.net/manual/en/language.types.float.php

« previous php.notes (#34580) next »