老师,这里不会出现浮点数精度问题吗
public function getAdjustedPrice($orderAmount)
{
// 固定金额
if ($this->type === self::TYPE_FIXED) {
// 为了保证系统健壮性,我们需要订单金额最少为 0.01 元
return max(0.01, $orderAmount - $this->value);
}
return number_format($orderAmount * (100 - $this->value) / 100, 2, '.', '');
}
return number_format($orderAmount * (100 - $this->value) / 100, 2, '.', '');
这里应该是会出现精度问题的
不会,
number_format
会做四舍五入: