Java Number Round roundNumberTo(double value, int decimals)

Here you can find the source of roundNumberTo(double value, int decimals)

Description

Rounds numbers down at the given decimal.

License

Open Source License

Parameter

Parameter Description
value a parameter
decimals a parameter

Declaration

public static String roundNumberTo(double value, int decimals) 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

public class Main {
    /**/*from   www  .  j ava2  s.c om*/
     * Rounds numbers down at the given decimal. 1.234 with decimal 1 will result in a string holding "1.2"
     * @param value
     * @param decimals
     * @return
     */
    public static String roundNumberTo(double value, int decimals) {
        return "" + Math.round(value * Math.pow(10, decimals))
                / Math.pow(10, decimals);
    }

    /**
     * Rounds numbers down at the given decimal. 1.234 with decimal 1 will result in a string holding "1.2"
     * @param value
     * @param decimals
     * @return
     */
    public static String roundNumberTo(float value, int decimals) {
        return "" + Math.round(value * Math.pow(10, decimals))
                / Math.pow(10, decimals);
    }
}

Related

  1. roundNicely(double dbl)
  2. roundNumber(double rowNumber, int roundingPoint)
  3. roundNumber(double theNumber, int places)
  4. roundNumber(float input, float rounding)
  5. roundNumber(String n)
  6. roundNumberToDouble(double value, int decimals)
  7. roundOff(double fraction, int precision)
  8. roundOffAmt(double dAmt)
  9. roundOffFileCount(int fileCount)