1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Utils/Traits/NumberFormatter.php
2019-04-04 15:49:13 +11:00

28 lines
574 B
PHP

<?php
namespace App\Utils\Traits;
/**
* Class NumberFormatter
* @package App\Utils\Traits
*/
trait NumberFormatter
{
private function formatValue($value) : string
{
return number_format($this->parseFloat($value), $this->precision, '.', '');
}
private function parseFloat($value) : float
{
// check for comma as decimal separator
if (preg_match('/,[\d]{1,2}$/', $value)) {
$value = str_replace(',', '.', $value);
}
$value = preg_replace('/[^0-9\.\-]/', '', $value);
return floatval($value);
}
}