Magento 製品を最も近い $x.90、$x.80、$x.85 などに丸める次のコードがありますが、入力は手動です。私が必要としているのは、ボタンを押すだけで価格を 10 セント単位で表示する新しい機能です。したがって、価格が $11.87 の場合は $11.90 にする必要があり、価格が $11.63 の場合は $11.60 にする必要があります。
どうすればいいですか?
protected function _round($price, $roundTo = 0.00, $type = 'normal')
{
$roundTo = ltrim(number_format($roundTo, 2, '.', ''), '0');
if ($type === 'normal') {
return round($price);
}
$safety = 99999999;
if ($type === 'up' || ($type === 'down' && $roundTo < $price)) {
while(substr($price, -(strlen($roundTo))) != $roundTo) {
if ($type === 'up') {
$price += .01;
}
else {
$price -= .01;
}
$price = number_format($price, 2, '.', '');
if (--$safety < 1) {
throw new Exception('Error');
}
}
return $price;
}
return false;
}