divide() public method

public divide ( java arg0 ) : global::java.math.BigDecimal
arg0 java
return global::java.math.BigDecimal
Exemplo n.º 1
0
        /**
         * Returns the string representation of this rational number as integer and fraction parts in the form "integerPart fractionNominator/fractionDenominator".
         *
         * <p>The integer part is omitted if it is 0 (when this absolute rational number is smaller than 1).</p>
         * <p>The fraction part is omitted it it is 0 (when this rational number is an integer).</p>
         * <p>If this rational number is 0, then "0" is returned.</p>
         *
         * <p>Example: <code>BigRational.valueOf(3.5).toIntegerRationalString()</code> returns <code>"3 1/2"</code>.</p>
         *
         * @return the integer and fraction rational string representation
         * @see #valueOf(int, int, int)
         */
        public String toIntegerRationalString()
        {
            BigDecimal fractionNumerator = numerator.remainder(denominator);
            BigDecimal integerNumerator  = numerator.subtract(fractionNumerator);
            BigDecimal integerPart       = integerNumerator.divide(denominator);

            StringBuilder result = new StringBuilder();

            if (integerPart.signum() != 0)
            {
                result.Append(integerPart);
            }
            if (fractionNumerator.signum() != 0)
            {
                if (result.Length > 0)
                {
                    result.Append(' ');
                }
                result.Append(fractionNumerator.abs());
                result.Append('/');
                result.Append(denominator);
            }
            if (result.Length == 0)
            {
                result.Append('0');
            }

            return(result.ToString());
        }
Exemplo n.º 2
0
 // Java Rev 1256.
 // TODO: figure out the roundingModes in  this implementation.
 // TODO:  Make this an explicit cast opearator?
 // TODO: Look at all these conversions.
 public BigDecimal ToBigDecimal()
 {
     BigDecimal numerator = new BigDecimal(this.numerator);
     BigDecimal denominator = new BigDecimal(this.denominator);
     return numerator.divide(denominator, 0);
 }
Exemplo n.º 3
0
 /**
  * Returns this rational number as a {@link BigDecimal} with the precision specified by the {@link MathContext}.
  *
  * @param mc the {@link MathContext} specifying the precision of the calculated result
  * @return the {@link BigDecimal}
  */
 public BigDecimal toBigDecimal(MathContext mc)
 {
     return(numerator.divide(denominator, mc));
 }
Exemplo n.º 4
0
 /**
  * Calculates this complex number divided by the given real {@link BigDecimal} value using the specified {@link MathContext}.
  *
  * <p>This methods <strong>does not</strong> modify this instance.</p>
  *
  * @param value the {@link BigDecimal} value to divide by
  * @param mathContext the {@link MathContext} used to calculate the result
  * @return the calculated {@link BigComplex} result
  */
 public BigComplex divide(BigDecimal value, MathContext mathContext)
 {
     return(valueOf(
                re.divide(value, mathContext),
                im.divide(value, mathContext)));
 }