Java Number Round roundMultiplier(double n)

Here you can find the source of roundMultiplier(double n)

Description

round Multiplier

License

Open Source License

Declaration

public static String roundMultiplier(double n) 

Method Source Code

//package com.java2s;

public class Main {
    public static String roundMultiplier(double n) {
        if (n >= 0.9) {
            n = Math.round(n);/*from w  w w .j a va 2 s.c  o m*/
            if (n >= 10) { // Round to nearest multiple of 10.
                n = Math.round(n / 10) * 10;
            }
            if (n >= 100) { // Round to nearest multiple of 10.
                n = Math.round(n / 100) * 100;
            }
            if (n >= 1000) { // Round to nearest multiple of 10.;
                n = Math.round(n / 1000) * 1000;
            }
            return Integer.toString((int) n);
        } else {
            String base = roundMultiplier(1. / n);
            if (base.equals("1"))
                return base;
            else
                return "1/" + base;
        }
    }
}

Related

  1. roundInventorySize(final int size)
  2. roundJs(double v, int n)
  3. roundLong(double a)
  4. roundM(int n, int m)
  5. roundMinAndMax(double min, double max, int tickCount)
  6. roundNearest(double v, double target)
  7. roundNicely(double dbl)
  8. roundNumber(double rowNumber, int roundingPoint)
  9. roundNumber(double theNumber, int places)