|
|
|
เกี่ยวกับการปัดเศษขึ้น แบบมีเงื่อนไขครับ PHP รบกวนเซียนช่วยทีครับ |
|
|
|
|
|
|
|
Code (PHP)
<?php
$input = '2.35';
$yournum = round(($input*2), 0)/2;
echo $yournum;
?>
|
|
|
|
|
Date :
2012-12-15 08:26:52 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อีกตัว
Code (PHP)
$x = floor($x * 2) / 2;
|
|
|
|
|
Date :
2012-12-15 08:27:15 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดูเพิ่มเติมครับ มันมีวิธีอยู่ครับ
Code (PHP)
<?php
/* Using PHP_ROUND_HALF_UP with 1 decimal digit precision */
echo round( 1.55, 1, PHP_ROUND_HALF_UP); // 1.6
echo round( 1.54, 1, PHP_ROUND_HALF_UP); // 1.5
echo round(-1.55, 1, PHP_ROUND_HALF_UP); // -1.6
echo round(-1.54, 1, PHP_ROUND_HALF_UP); // -1.5
/* Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision */
echo round( 1.55, 1, PHP_ROUND_HALF_DOWN); // 1.5
echo round( 1.54, 1, PHP_ROUND_HALF_DOWN); // 1.5
echo round(-1.55, 1, PHP_ROUND_HALF_DOWN); // -1.5
echo round(-1.54, 1, PHP_ROUND_HALF_DOWN); // -1.5
/* Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision */
echo round( 1.55, 1, PHP_ROUND_HALF_EVEN); // 1.6
echo round( 1.54, 1, PHP_ROUND_HALF_EVEN); // 1.5
echo round(-1.55, 1, PHP_ROUND_HALF_EVEN); // -1.6
echo round(-1.54, 1, PHP_ROUND_HALF_EVEN); // -1.5
/* Using PHP_ROUND_HALF_ODD with 1 decimal digit precision */
echo round( 1.55, 1, PHP_ROUND_HALF_ODD); // 1.5
echo round( 1.54, 1, PHP_ROUND_HALF_ODD); // 1.5
echo round(-1.55, 1, PHP_ROUND_HALF_ODD); // -1.5
echo round(-1.54, 1, PHP_ROUND_HALF_ODD); // -1.5
?>
http://php.net/manual/en/function.round.php
|
|
|
|
|
Date :
2012-12-15 08:28:22 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|