Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Apr 18, 2022
1 parent b8a4bd4 commit f502452
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Helpers/NumberHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace AnourValar\LaravelAtom\Helpers;

class NumberHelper
{
/**
* Canonize
*
* @param int|float|string|null $amount
* @return int|null
*/
public function encodeMultiple(int|float|string|null $amount): ?int
{
if (is_null($amount)) {
return null;
}

return round($amount, config('atom.number.multiple_round')) * config('atom.number.multiple');
}

/**
* Formatting (for display)
*
* @param int|null $amount
* @return float|null
*/
public function decodeMultiple(?int $amount): float|null
{
if (! isset($amount)) {
return null;
}

return round($amount / config('atom.number.multiple'), config('atom.number.multiple_round'));
}
}
5 changes: 5 additions & 0 deletions src/resources/config/atom.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
'optimistic_transaction' => AnourValar\LaravelAtom\Strategies\OptimisticTransactionStrategy::class,
],
],

'number' => [
'multiple' => 100,
'multiple_round' => 2,
],
];

0 comments on commit f502452

Please sign in to comment.