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 20:28:53 +11:00

28 lines
580 B
PHP

<?php
namespace App\Utils\Traits;
/**
* Class NumberFormatter
* @package App\Utils\Traits
*/
trait NumberFormatter
{
private function formatValue($value, $precision) : string
{
return number_format($this->parseFloat($value), $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);
}
}