Cambio en nombre de metodo y uso de valor maximo para UF

This commit is contained in:
Juan Pablo Vial
2025-04-29 11:20:49 -04:00
parent 5d939f970b
commit c3b7427f60

View File

@ -27,7 +27,7 @@ class Valor
public function toPesos(string $value, null|string|DateTimeInterface $date = null, bool $force = false): int public function toPesos(string $value, null|string|DateTimeInterface $date = null, bool $force = false): int
{ {
$date = $this->getDateTime($date); $date = $this->getDateTime($date);
if ($this->isFloat($value) or $force) { if ($this->inUF($value) or $force) {
return round($value * $this->ufService->get($date)); return round($value * $this->ufService->get($date));
} }
return (int) $value; return (int) $value;
@ -35,7 +35,7 @@ class Valor
public function toUF(string $value, null|string|DateTimeInterface $date = null, bool $force = false): float public function toUF(string $value, null|string|DateTimeInterface $date = null, bool $force = false): float
{ {
$date = $this->getDateTime($date); $date = $this->getDateTime($date);
if ($this->isFloat($value) and !$force) { if ($this->inUF($value) and !$force) {
return (float) $value; return (float) $value;
} }
return $value / $this->ufService->get($date); return $value / $this->ufService->get($date);
@ -101,9 +101,12 @@ class Valor
{ {
return (float) str_replace(',', '', $value); return (float) str_replace(',', '', $value);
} }
protected function isFloat(string|int|float $value): bool protected function inUF(string|int|float $value, float $check = 10000): bool
{ {
if (!is_string($value)) { if (!is_string($value)) {
if ($value >= $check) { // Valor arbitrario mayor que el cual no es UF
return false;
}
return is_float($value); return is_float($value);
} }
$cleaned = $this->clean($value); $cleaned = $this->clean($value);