开发者

is there a ceil() alternative to turn 6523.70 to 6523 and not turn 6523.20

开发者 https://www.devze.com 2022-12-16 00:57 出处:网络
the function of ceil() in php is not useful in my case, because i want if the number contains from 0.50 to 0.99 then it\'s will cei开发者_如何学运维l it, if it\'s smaller than 0.50 it\'s will not do a

the function of ceil() in php is not useful in my case, because i want if the number contains from 0.50 to 0.99 then it's will cei开发者_如何学运维l it, if it's smaller than 0.50 it's will not do anything.

example:

6523.70 will be 6524

but

6523.49 will stay same.

i hope you got it guys :)

Thanks


This will only change numbers which are >= .5

function weirdRounding($num) {
    if ($num - floor($num) >= .5) {
        return ceil($num);
    }
    return $num;
}

weirdRounding(6523.70) --> 6524
weirdRounding(6523.49) --> 6523.49


Forgive me, I haven't written PHP in a while.

if( ( $var - intval( $var ) ) >= 0.5 ) $var = ceil( $var )

Thus,

6523.70 to 6524 and 6523.49 stays 6523.49

0

精彩评论

暂无评论...
验证码 换一张
取 消