Hoan thien core finance v2 - Calculation Pipeline, Form Templates
This commit is contained in:
21
app/Services/Calculation/RoundingRule.php
Normal file
21
app/Services/Calculation/RoundingRule.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Calculation;
|
||||
|
||||
enum RoundingRule: string
|
||||
{
|
||||
case NONE = 'none'; // Không làm tròn
|
||||
case UNIT = 'unit'; // Làm tròn đến đồng (số nguyên)
|
||||
case THOUSAND = 'thousand'; // Làm tròn đến nghìn
|
||||
case MILLION = 'million'; // Làm tròn đến triệu
|
||||
|
||||
public function apply(float $value): int
|
||||
{
|
||||
return match ($this) {
|
||||
self::NONE => (int) $value,
|
||||
self::UNIT => (int) round($value),
|
||||
self::THOUSAND => (int) (round($value / 1000) * 1000),
|
||||
self::MILLION => (int) (round($value / 1000000) * 1000000),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user