Java Double Number Divide divide(float left, float right)

Here you can find the source of divide(float left, float right)

Description

Divides the given left float value by the given right float value.

License

Open Source License

Parameter

Parameter Description
left the left float value
right the right float value

Return

the division result

Declaration

public static float divide(float left, float right) 

Method Source Code

//package com.java2s;
/**//w ww.  j  a v  a  2s.  com
 * AADL-Utils
 * 
 * Copyright ? 2012 TELECOM ParisTech and CNRS
 * 
 * TELECOM ParisTech/LTCI
 * 
 * Authors: see AUTHORS
 * 
 * This program is free software: you can redistribute it and/or modify 
 * it under the terms of the Eclipse Public License as published by Eclipse,
 * either version 1.0 of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Eclipse Public License for more details.
 * You should have received a copy of the Eclipse Public License
 * along with this program.  If not, see 
 * http://www.eclipse.org/org/documents/epl-v10.php
 */

import java.math.BigDecimal;

public class Main {
    /**
     * Divides the given left float value by the given right float value.
     * 
     * @param left the left float value
     * @param right the right float value
     * @return the division result
     */
    public static float divide(float left, float right) {
        BigDecimal iLeft = new BigDecimal(left + "");
        BigDecimal iRight = new BigDecimal(right + "");

        try {
            return iLeft.divide(iRight).floatValue();
        } catch (Exception e) {
            return iLeft.divide(iRight, BigDecimal.ROUND_HALF_DOWN).floatValue();
        }
    }
}

Related

  1. divide(Double numerator, Double denominator)
  2. divide(double v1, double v2)
  3. divide(double x, double y, int scale, RoundingMode roundingMode)
  4. divide(final double n1, final double n2)
  5. divide(float a, float b)
  6. divide(Number numerator, Number denominator)
  7. divide(Object dividend, Object divisor)
  8. divide(Object num1, Object num2)
  9. divide(String num1, String num2)