src/CryptoQuantity.php
public static function fromFloat($float_value, $precision = null)
    {
        if ($precision === null) {
            $precision = static::$PRECISION;
        }

        // left of decimal point
        $rounded_float = intval(round($float_value));
        $big_integer_int = (new BigInt($rounded_float))->multiply(self::precisionUnitsAsBigInt(1, $precision));

        // right of decimal point
        $rounded_decimal = intval(round(floatval($float_value - $rounded_float) * pow(10, $precision)));
        $big_integer_decimal = new BigInt($rounded_decimal);

        // add the integer value and the decimal value
        return new static($big_integer_int->add($big_integer_decimal), $precision);
    }
public static function fromFloat($float_value, $precision = null)
    {
        if ($precision === null) {
            $precision = static::$PRECISION;
        }

        // left of decimal point
        $rounded_float = intval(round($float_value));
        $big_integer_int = (new BigInt($rounded_float))->multiply(self::precisionUnitsAsBigInt(1, $precision));

        // right of decimal point
        $rounded_decimal = intval(round(floatval($float_value - $rounded_float) * pow(10, $precision)));
        $big_integer_decimal = new BigInt($rounded_decimal);

        // add the integer value and the decimal value
        return new static($big_integer_int->add($big_integer_decimal), $precision);
    }
public static function fromFloat ( $ float_value , $ precision = null ) { if ( $ precision === null ) { $ precision = static :: $ PRECISION ; } // left of decimal point $ rounded_float = intval ( round ( $ float_value ) ) ; $ big_integer_int = ( new BigInt ( $ rounded_float ) ) -> multiply ( self :: precisionUnitsAsBigInt ( 1 , $ precision ) ) ; // right of decimal point $ rounded_decimal = intval ( round ( floatval ( $ float_value - $ rounded_float ) * pow ( 10 , $ precision ) ) ) ; $ big_integer_decimal = new BigInt ( $ rounded_decimal ) ; // add the integer value and the decimal value return new static ( $ big_integer_int -> add ( $ big_integer_decimal ) , $ precision ) ; }
Creates a new quantity from a float value
@param  float   $float_value   The amount as a float
@param  integer $precision     Number of decimal places of precision
@return CryptoQuantity         The new CryptoQuantity object
Creates a new quantity from a float value