how can i add round to the nearest multiple of 10 to request I already have:
Clothes::query()->update ([ 'price_kiev_1' => \DB::raw("price_kiev_1 price_kiev_1 / 100 * $value") ]);
in the request i increase the price by % and I want to round it up in the same request
CodePudding user response:
Try something like :
Clothes::query()->update([
'price_kiev_1' => \DB::raw("ROUND(price_kiev_1 price_kiev_1 / 100 * $value, -1)")
]);
The second parameter of the ROUND()
function defines the position of the rounding.
mysql> SELECT ROUND(1.298, 1);
-> 1.3
mysql> SELECT ROUND(1.298, 0);
-> 1
mysql> SELECT ROUND(23.298, -1);
-> 20