Java Double Number Round round(double value, int scalar, int standard)

Here you can find the source of round(double value, int scalar, int standard)

Description

round

License

Open Source License

Declaration

public static double round(double value, int scalar, int standard) throws Exception 

Method Source Code

//package com.java2s;
/**//from   w  w  w. j a  v  a  2  s  .  co m
 * Copyright (C) 2002-2005 WUZEWEN. All rights reserved.
 * WUZEWEN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {

    public static double round(double value, int scalar, int standard) throws Exception {
        return Double.parseDouble(round(String.valueOf(value), scalar, standard));
    }

    public static String round(String value, int scalar, int standard) throws Exception {

        String back = null;
        int point = value.indexOf(".");
        if (point > -1) {
            int len = value.length() - point + 1;
            if (len <= scalar) {
                back = value;
            } else {
                back = value.substring(0, point + scalar + 1);
                String vsTemp = value.substring(point + scalar + 1, point + scalar + 2);
                if (Integer.parseInt(vsTemp) >= standard) {
                    back = String.valueOf(Integer.parseInt(back) + 1);
                }
            }
        } else {
            back = value;
        }
        return back;
    }
}

Related

  1. round(double value, int power)
  2. round(double value, int precision)
  3. round(double value, int precision)
  4. round(double value, int precision)
  5. round(double value, int roundingFactor)
  6. round(double valueToRound, int numberOfDecimalPlaces)
  7. round(double valueToTruncate, int requiredDecimalPlaces)
  8. round(double what, int howmuch)
  9. round(double x)