unscaledValue() public method

public unscaledValue ( ) : global::java.math.BigInteger
return global::java.math.BigInteger
Beispiel #1
0
        /**
         * Creates a rational number of the specified {@link BigDecimal} value.
         *
         * @param value the double value
         * @return the rational number
         */
        public static BigRational valueOf(BigDecimal value)
        {
            if (value.compareTo(BigDecimal.ZERO) == 0)
            {
                return(ZERO);
            }
            if (value.compareTo(BigDecimal.ONE) == 0)
            {
                return(ONE);
            }

            int scale = value.scale();

            if (scale == 0)
            {
                return(new BigRational(value, BigDecimal.ONE));
            }
            else if (scale < 0)
            {
                BigDecimal n = new BigDecimal(value.unscaledValue()).multiply(BigDecimal.ONE.movePointLeft(value.scale()));
                return(new BigRational(n, BigDecimal.ONE));
            }
            else
            {
                BigDecimal n = new BigDecimal(value.unscaledValue());
                BigDecimal d = BigDecimal.ONE.movePointRight(value.scale());
                return(new BigRational(n, d));
            }
        }