Java Double Number Divide divideInts(int numerator, int denominator)

Here you can find the source of divideInts(int numerator, int denominator)

Description

Provides exact division of two integer values by using BigDecimal division.

License

Apache License

Parameter

Parameter Description
numerator a parameter
denominator a parameter

Declaration

public static double divideInts(int numerator, int denominator) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;

public class Main {
    /**// w  w  w.  ja  va2  s  .  c o  m
     * The scale for calculations with BigDecimal.
     */
    private static final int DECIMAL_SCALE = 10;

    /**
     * Provides exact division of two integer values by using BigDecimal
     * division.
     * 
     * @param numerator
     * @param denominator
     * @return
     */
    public static double divideInts(int numerator, int denominator) {
        BigDecimal result = BigDecimal.valueOf(numerator).divide(BigDecimal.valueOf(denominator), DECIMAL_SCALE,
                BigDecimal.ROUND_HALF_UP);
        return result.doubleValue();
    }
}

Related

  1. divide(String thisVal, String addVal)
  2. divide4Money(Double value1, Double value2)
  3. divideComplex(double realOne, double imagOne, double realTwo, double imagTwo)
  4. divideDouble(double first, double second)
  5. divideDouble(double first, double second, int scale, int roundingMode)
  6. divideNumber(Object divisor, Object dividend)
  7. divZ(double z)
  8. getIntDividedCeil(final int nDividend, final int nDivisor)
  9. getLongDivided(final long nDividend, final long nDivisor, @Nonnull final RoundingMode eRoundingMode)