Skip to content

Commit

Permalink
fix: rounding precision
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlmaier committed Nov 20, 2024
1 parent 2447d1f commit f8266d3
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions backend/app/Helper/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,12 @@ public static function format(float|int $amount, string $currencyCode, string $l
return $formatter->formatCurrency($amount, $currencyCode);
}

public static function round(float $value, $precision = 2): float
public static function round(float $value, $precision = 1): float
{
$fraction = $value - floor($value);

if ($fraction >= 0.99) {
return ceil($value);
} elseif ($fraction <= 0.01) {
return floor($value);
} else {
return round(
num: $value,
precision: $precision,
mode: PHP_ROUND_HALF_UP
);
}
return round(
num: $value,
precision: $precision,
mode: PHP_ROUND_HALF_UP
);
}
}

0 comments on commit f8266d3

Please sign in to comment.