class_mcNumber.inc.php 1.1 KB
<?php
/** 
 * @copyright (c) 2014, netz.coop eG
 */
class mcNumber {

	public static function round2($param_number) {
		return round($param_number, 2);
	}	
	
	public static function form2($param_number) {
		return number_format(round($param_number, 2), 2, ",", ".");
	}
	public static function form5($param_number) {
		return number_format(round($param_number, 5), 2, ",", ".");
	}
	
	public static function transformStringToFloat($param_string) {
//		D::ulli($param_string);
		if(strpos($param_string, ',')!==false) {
			
			$param_string = str_replace(',', '.', $param_string);
			
		}		
//		D::ulli('return '.$price);
		return $param_string;
	}
	
	public static function transformProcentToInt($param_procent) {
		if(strpos($param_procent, '%')!==false) {
			$percent = str_replace('%', '', $param_procent);
			$percent = trim($percent);
			

		} else if(strpos($param_procent, '0,')!==false) {
			$percent = 100*mcNumber::transformStringToFloat($param_procent);
			
			
		} else {
			$percent = $param_procent;

		}
//		D::li('transformProcentToInt '.$param_procent.' => '.$percent);
		return trim($percent);
		
	}
}
?>