Deprecated: Function create_function() is deprecated in /www/wwwroot/fave.top/usr/plugins/AntiSpam/Plugin.php on line 75
PHP正负数转换 - Nermif

正数转负数

$number = 99;
$number *= -1;
echo $number;   //输出 -99

负数转正数

$number = -11;
$result = abs($number);
echo $result;   //输出 11

封装成方法使用

function plus_minus_conversion($number = 0){
    return $number > 0 ? -1 * $number : abs($number);
}

echo plus_minus_conversion(100.58);

标签: PHP, 正数转负数, 负数转正数, 正负数互转

添加新评论