<?php

namespace Types;

class Double {
  
  

  
  

    // --- Statische Methoden ---
  
  public static function decimalSeparator() { 
    
    
    // --- BLOCK: main ---
    return _('.');
    
  }

  public static function thousandsSeparator() { 
    
    
    // --- BLOCK: main ---
    return '';
    
  }

  public static function pattern() { 
    
    
    // --- BLOCK: main ---
    
		$escape = function ($x) { return $x == '.' ? '\.' : $x; };
		return '-?[0-9' . self::thousandsSeparator() . ']+(?:' . self::decimalSeparator() . '\d+)?';
    
  }

  public static function parse($x) { 
    
    
    // --- BLOCK: main ---
    
		$x = str_replace(self::thousandsSeparator(), '', $x);
		$x = str_replace(self::decimalSeparator(), '.', $x);
		$x = preg_replace('/[^0-9\-\.]/', '', $x);
		return json_decode($x);
	
    
  }

  public static function unpack($x) { 
    
    
    // --- BLOCK: main ---
    
		if ($x === null) return null;
		if (is_float($x)) return $x;
		return floatval(json_decode($x));
	
    
  }

  public static function print($x) { 
    
    
    // --- BLOCK: main ---
    
		
		$x = number_format($x, 12, self::decimalSeparator(), self::thousandsSeparator());
		while (preg_match('/'.(self::decimalSeparator() == '.' ? '\.' : self::decimalSeparator()).'[0-9]+?0$/', $x)) $x = substr($x, 0, strlen($x)-1);
		return $x;
	
    
  }


  
  

  
  
}



