Skip to content

Instantly share code, notes, and snippets.

@mahammad
Last active November 3, 2021 10:49
Show Gist options
  • Save mahammad/643008c838c1bbc0137d84c0418a98ff to your computer and use it in GitHub Desktop.
Save mahammad/643008c838c1bbc0137d84c0418a98ff to your computer and use it in GitHub Desktop.
PHP'de sayı yuvarlama fonksiyonu
<?php
if (!function_exists('round_up')) {
/**
* @param float $value
* @param integer $places
* @return float
*/
function round_up($value, $places=0)
{
if ($places < 0) { $places = 0; }
$mult = pow(10, $places);
return ceil($value * $mult) / $mult;
}
}
if (!function_exists('round_out')) {
/**
* @param float $value
* @param integer $places
* @return float
*/
function round_out($value, $places=0)
{
if ($places < 0) { $places = 0; }
$mult = pow(10, $places);
return ($value >= 0 ? ceil($value * $mult):floor($value * $mult)) / $mult;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment