mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 11:07:31 -04:00 
			
		
		
		
	
		
			
				
	
	
		
			28 lines
		
	
	
		
			580 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			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);
 | |
|     }
 | |
| 
 | |
| } |