mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
move to round() instead of number_format()
This commit is contained in:
+15
-5
@@ -5,15 +5,25 @@
|
||||
class Helpers
|
||||
{
|
||||
/**
|
||||
* normalize price
|
||||
*
|
||||
* @return float
|
||||
* Normalize prices
|
||||
*/
|
||||
public static function normalizePrice($price)
|
||||
public static function normalizePrice($price): float
|
||||
{
|
||||
return (is_string($price)) ? floatval($price) : $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rounding mode
|
||||
*/
|
||||
public static function roundMode($config): int
|
||||
{
|
||||
if (isset($config['round_mode']) && $config['round_mode'] == 'up') {
|
||||
return PHP_ROUND_HALF_UP;
|
||||
}
|
||||
|
||||
return PHP_ROUND_HALF_DOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if array is multi dimensional array
|
||||
* This will only check the first element of the array if it is still an array
|
||||
@@ -61,7 +71,7 @@ public static function formatValue($value, $formatNumber, $config)
|
||||
}
|
||||
|
||||
if ($formatNumber || $config['format_numbers']) {
|
||||
return floatval(number_format($value, $config['decimals'], $config['dec_point'], $config['thousands_sep']));
|
||||
return round($value, $config['decimals'], self::roundMode($config));
|
||||
} else {
|
||||
return floatval($value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user