Oct 01

Thatโ€™s a job for the BigDecimal class


public static String formatToSignificant(double value, 
   int significant)
{
   MathContext mathContext = new MathContext(significant, 
      RoundingMode.DOWN);
   BigDecimal bigDecimal = new BigDecimal(value, 
      mathContext);
   return bigDecimal.toPlainString();
} 

written by objects \\ tags: ,


Leave a Reply

You must be logged in to post a comment.