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.math.MathContext;

public class Main {
    /**
     * Returns a string representation of number rounded to given number of
     * significant figures
     *
     * @param value
     * @param significantFigures
     * @return String.
     */
    public static String roundToString(double value, int significantFigures) {
        MathContext mc = new MathContext(significantFigures);
        BigDecimal num = new BigDecimal(value);
        return num.round(mc).toPlainString();
    }
}