Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {

    public static String formatPercentWithFixedFractionDigit(BigDecimal number, int fractionDigit) {
        String result = "0";

        if (number != null) {
            number = number.multiply(new BigDecimal("100"));
            DecimalFormat formatter = new DecimalFormat();
            formatter.setMaximumFractionDigits(fractionDigit);
            formatter.setMinimumFractionDigits(fractionDigit);

            result = formatter.format(number);
        }
        return result;
    }
}