Litipk\BigNumbers\Decimal::create PHP Method

create() public static method

Decimal "constructor".
public static create ( mixed $value, integer $scale = null, boolean $removeZeros = false ) : Decimal
$value mixed
$scale integer
$removeZeros boolean If true then removes trailing zeros from the number representation
return Decimal
    public static function create($value, $scale = null, $removeZeros = false)
    {
        if (is_int($value)) {
            return self::fromInteger($value);
        } elseif (is_float($value)) {
            return self::fromFloat($value, $scale, $removeZeros);
        } elseif (is_string($value)) {
            return self::fromString($value, $scale, $removeZeros);
        } elseif ($value instanceof Decimal) {
            return self::fromDecimal($value, $scale);
        } else {
            throw new InvalidArgumentTypeException(['int', 'float', 'string', 'Decimal'], is_object($value) ? get_class($value) : gettype($value), 'Invalid argument type.');
        }
    }

Usage Example

Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === null) {
         return null;
     }
     try {
         return Decimal::create($value);
     } catch (\Exception $e) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), '0.0');
     }
 }
All Usage Examples Of Litipk\BigNumbers\Decimal::create