Java Number Round roundNicely(double dbl)

Here you can find the source of roundNicely(double dbl)

Description

round Nicely

License

BSD License

Declaration

private static String roundNicely(double dbl) 

Method Source Code

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

public class Main {
    private static String roundNicely(double dbl) {
        long rounded = Math.round((dbl * 100.0));
        String result = String.valueOf(((double) rounded) / 100.0);
        if (dbl < 10) {
            result = String.valueOf(Math.round(dbl * 100.0) / 100.0);
        } else if (dbl < 100) {
            result = String.valueOf(Math.round(dbl * 10.0) / 10.0);
        } else {/*from   ww w .jav a 2s  .c om*/
            result = String.valueOf(((long) dbl));
        }
        if (result.endsWith(".0")) {
            result = result.replace(".0", "");
        }
        return result;
    }
}

Related

  1. roundLong(double a)
  2. roundM(int n, int m)
  3. roundMinAndMax(double min, double max, int tickCount)
  4. roundMultiplier(double n)
  5. roundNearest(double v, double target)
  6. roundNumber(double rowNumber, int roundingPoint)
  7. roundNumber(double theNumber, int places)
  8. roundNumber(float input, float rounding)
  9. roundNumber(String n)