Java Number Round roundFloatToUnitInverse(final float graphValue, final float graphUnit)

Here you can find the source of roundFloatToUnitInverse(final float graphValue, final float graphUnit)

Description

Round floating value to an inverse long value.

License

Open Source License

Parameter

Parameter Description
graphValue a parameter
graphUnit a parameter

Declaration

public static long roundFloatToUnitInverse(final float graphValue, final float graphUnit) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2005, 2016 Wolfgang Schramm and Contributors
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation version 2 of the License./* www  . j av a2s  .  c  o m*/
 *
 * 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 GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
 *******************************************************************************/

public class Main {
    /**
     * Round floating value to an inverse long value.
     * 
     * @param graphValue
     * @param graphUnit
     * @return
     */
    public static long roundFloatToUnitInverse(final float graphValue, final float graphUnit) {

        if (graphUnit < 1) {

            if (graphValue < 0) {

                final float value1 = graphValue / graphUnit;
                final float value2 = value1 - 0.5f;
                final long value3 = (long) (value2);

                return value3;

            } else {

                final float value1 = graphValue / graphUnit;
                final float value2 = value1 + 0.5f;
                final long value3 = (long) (value2);

                return value3;
            }

        } else {

            // graphUnit > 1

            return (long) (graphValue * graphUnit);
        }
    }
}

Related

  1. rounder(float value, int digits)
  2. roundf(float value)
  3. roundFileLength(long nbytes)
  4. roundFloat(float value, int afterDecimalPoint)
  5. roundFloatToPlace(float f, int place)
  6. roundFormat(final int numPrec, final double number)
  7. RoundFullUp(double d)
  8. roundHalfAway(double d)
  9. RoundHalfUp(double d)