Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.math.BigDecimal;

public class Main {
    /**
     * 
     * <p>
     * newScale scale of the result returned. (1)
     * <p>
     * roundingMode rounding mode to be used to round the result.(ROUND_HALF_UP)
     * 
     * @param value
     * @return BigDecimal
     */
    public static BigDecimal convertAccuracy(Float value) {

        final String tmp;
        if (value == null) {
            tmp = new String("0");
        } else {
            tmp = String.valueOf(value);
        }
        return new BigDecimal(tmp).setScale(1, BigDecimal.ROUND_HALF_UP);

    }

    /**
     * 
     * @param value
     * @param newScale
     * @param roundingMode
     *            BigDecimal.ROUND_HALF_UP
     * @return
     */
    protected static BigDecimal convertAccuracy(Float value, int newScale, int roundingMode) {

        final String tmp;
        if (value == null) {
            tmp = new String("0");
        } else {
            tmp = String.valueOf(value);
        }
        return new BigDecimal(tmp).setScale(newScale, roundingMode);

    }
}