public static function unFormatDecimal($decimalString) {

		if(trim($decimalString) == '') {
			return NAN;
		}

		// remove a leading "+"

		$decimalString = rtrim('+', trim($decimalString));

		// only a decimal separator ("," or ".")

		if(preg_match('/^\-?\d+([,.]\d+)?$/', $decimalString)) {
			return (float) (str_replace(',', '.', $decimalString));
		}
		
		// "," as thousands separator "." as decimal separator

		if(preg_match('/^\-?[1-9]\d{0,2}((,|\')\d{3})*(\.\d+)?$/', $decimalString)) {
			return (float) (str_replace(array(',', '\''), array('', ''), $decimalString));
		}
		
		// "." as thousands separator "," as decimal separator
		
		if(preg_match('/^\-?[1-9]\d{0,2}(\.\d{3})*(,\d+)?$/', $decimalString)) {
			return (float) (str_replace(array('.', ','), array('', '.'), $decimalString));
		}
		
		// try type casting

		return (float) $decimalString;
	}
public static function unFormatDecimal($decimalString) {

		if(trim($decimalString) == '') {
			return NAN;
		}

		// remove a leading "+"

		$decimalString = rtrim('+', trim($decimalString));

		// only a decimal separator ("," or ".")

		if(preg_match('/^\-?\d+([,.]\d+)?$/', $decimalString)) {
			return (float) (str_replace(',', '.', $decimalString));
		}
		
		// "," as thousands separator "." as decimal separator

		if(preg_match('/^\-?[1-9]\d{0,2}((,|\')\d{3})*(\.\d+)?$/', $decimalString)) {
			return (float) (str_replace(array(',', '\''), array('', ''), $decimalString));
		}
		
		// "." as thousands separator "," as decimal separator
		
		if(preg_match('/^\-?[1-9]\d{0,2}(\.\d{3})*(,\d+)?$/', $decimalString)) {
			return (float) (str_replace(array('.', ','), array('', '.'), $decimalString));
		}
		
		// try type casting

		return (float) $decimalString;
	}
public static function unFormatDecimal ( $ decimalString ) { if ( trim ( $ decimalString ) == '' ) { return NAN ; } // remove a leading "+" $ decimalString = rtrim ( '+' , trim ( $ decimalString ) ) ; // only a decimal separator ("," or ".") if ( preg_match ( '/^\-?\d+([,.]\d+)?$/' , $ decimalString ) ) { return ( float ) ( str_replace ( ',' , '.' , $ decimalString ) ) ; } // "," as thousands separator "." as decimal separator if ( preg_match ( '/^\-?[1-9]\d{0,2}((,|\')\d{3})*(\.\d+)?$/' , $ decimalString ) ) { return ( float ) ( str_replace ( array ( ',' , '\'' ) , array ( '' , '' ) , $ decimalString ) ) ; } // "." as thousands separator "," as decimal separator if ( preg_match ( '/^\-?[1-9]\d{0,2}(\.\d{3})*(,\d+)?$/' , $ decimalString ) ) { return ( float ) ( str_replace ( array ( '.' , ',' ) , array ( '' , '.' ) , $ decimalString ) ) ; } // try type casting return ( float ) $ decimalString ; }
Strips decimal strings from everything but decimal point and negative prefix
and returns the result as float

@param string $decimalString
@return float | NaN
Strips decimal strings from everything but decimal point and negative prefix and returns the result as float