mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 22:01:48 +00:00
move to round() instead of number_format()
This commit is contained in:
+1
-3
@@ -10,9 +10,7 @@
|
|||||||
|
|
||||||
'decimals' => env('LARAVEL_CART_DECIMALS', 0),
|
'decimals' => env('LARAVEL_CART_DECIMALS', 0),
|
||||||
|
|
||||||
'dec_point' => env('LARAVEL_CART_DEC_POINT', '.'),
|
'round_mode' => env('LARAVEL_CART_ROUND_MODE', 'down'),
|
||||||
|
|
||||||
'thousands_sep' => env('LARAVEL_CART_THOUSANDS_SEP', ','),
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ---------------------------------------------------------------
|
* ---------------------------------------------------------------
|
||||||
|
|||||||
+15
-5
@@ -5,15 +5,25 @@
|
|||||||
class Helpers
|
class Helpers
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* normalize price
|
* Normalize prices
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*/
|
*/
|
||||||
public static function normalizePrice($price)
|
public static function normalizePrice($price): float
|
||||||
{
|
{
|
||||||
return (is_string($price)) ? floatval($price) : $price;
|
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
|
* check if array is multi dimensional array
|
||||||
* This will only check the first element of the array if it is still an 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']) {
|
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 {
|
} else {
|
||||||
return floatval($value);
|
return floatval($value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user