Java Double Number Format format(double number, int precision)

Here you can find the source of format(double number, int precision)

Description

format

License

Open Source License

Declaration

public static double format(double number, int precision) 

Method Source Code

//package com.java2s;
/*//from  w  w w . j av a 2  s  .c  o m
 * Copyright 2011-2016 ZXC.com All right reserved. This software is the confidential and proprietary information of
 * ZXC.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into with ZXC.com.
 */

public class Main {

    public static double format(double number, int precision) {
        int tmp = 1;
        for (int i = 0; i < precision; i++) {
            tmp *= 10;
        }
        int value = (int) Math.round(number * tmp);
        return (value * 1d) / tmp;
    }
}

Related

  1. format(Double decimal)
  2. format(double num, int n)
  3. format(double number)
  4. format(Double number)
  5. format(double number, int nums)
  6. format(double size, String type)
  7. format(double val, int n, int w)
  8. format(double value, int decimalPlaces)
  9. format(double value, int digits)