Java Number Round roundSimpleNumberUnits(final long graphDefaultUnit)

Here you can find the source of roundSimpleNumberUnits(final long graphDefaultUnit)

Description

round Simple Number Units

License

Open Source License

Declaration

public static int roundSimpleNumberUnits(final long graphDefaultUnit) 

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./*from   w  w  w  .  j ava2s.com*/
 *
 * 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 {
    public static int roundSimpleNumberUnits(final long graphDefaultUnit) {

        float unit = graphDefaultUnit;
        int multiplier = 1;

        while (unit > 20) {
            multiplier *= 10;
            unit /= 10;
        }

        unit = //
                //
                unit >= 10 ? 10 : //
                        unit >= 5 ? 5 : //
                                unit >= 2 ? 2 : //
                                        1;

        unit *= multiplier;

        return (int) unit;
    }
}

Related

  1. roundSec(int sec)
  2. roundSec(long milli)
  3. roundSig(double d, int n)
  4. roundSignificant(double d, int numDigit, boolean keepInteger)
  5. roundSignificant(double value)
  6. roundSizes(float[] sizes)
  7. roundSonekiSuii(double amount1, double amount2)
  8. roundsToTicks(double x)
  9. roundStr(Double value, int decimal)