Skip to content

Commit

Permalink
feat: implement rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlmaier committed Nov 20, 2024
1 parent 65ea823 commit 2447d1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions backend/app/Helper/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ public static function format(float|int $amount, string $currencyCode, string $l

public static function round(float $value, $precision = 2): float
{
return round(
num: $value,
precision: $precision,
mode: PHP_ROUND_HALF_UP
);
$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
);
}
}
}
2 changes: 1 addition & 1 deletion frontend/src/utilites/currency.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const formatCurrency = (value: number | string, currency = 'USD') => {
const formatter = new Intl.NumberFormat('en-US', {
const formatter = new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: currency,
minimumFractionDigits: 2,
Expand Down

0 comments on commit 2447d1f

Please sign in to comment.