Files
hqland-app/app/Services/Calculation/RoundingRule.php

22 lines
670 B
PHP

<?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),
};
}
}