note 84766 deleted from function.ceil by mgf
| From: | mgf@php.net | Date: | Tue, 29 Jul 2008 12:41:27 +0000 |
| Subject: | note 84766 deleted from function.ceil by mgf | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142892@lists.php.net to get a copy of this message | ||
Note Submitter: fuck at you dot com
----
What the hell is with all of the string manipulation when you are carrying out a mathematical
operation?
Use something like:
sub round_it {
my $num = shift;
my $sig = shift;
my $neg = 0;
if ($num < 0) {
$num += -(2 * $num);
$neg = 1;
}
my $ret = int($num * (10 ** $sig)) / (10 ** $sig);
if ($ret < $num) {
if (($num * (10 ** length($ret))) % ($ret * (10 ** length($ret))) > 5) {
$ret += 100 / (10 ** length($ret));
}
}
return $neg == 1 ? -$ret : $ret;
}
for it to be done logically and correctly.
Jesus. No wonder the term "PHP programmer" is also meant to mean "Idiot".