由於歷史緣由,在Laravel 5.3版本 使用 Eloquent 的 increment
出現了精度丟失,this
重寫incrementOrDecrementAttributeValue
方法,使用 bcadd
進行計算,保留2位小數。code
protected function incrementOrDecrementAttributeValue($column, $amount, $method) { $this->{$column} = bcadd($this->{$column}, ($method == 'increment' ? $amount : $amount * -1), 2); $this->syncOriginalAttribute($column); }