Here you can find the source of roundNumberTo(double value, int decimals)
Parameter | Description |
---|---|
value | a parameter |
decimals | a parameter |
public static String roundNumberTo(double value, int decimals)
//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); } }