-4

How do i round a BigDecimal to 2 decimal places and then to one significant figure?

Thanks

user1406186
  • 940
  • 3
  • 16
  • 28
  • http://stackoverflow.com/questions/14515640/how-to-display-a-number-with-always-2-decimal-points-using-bigdecimal – IntelliJ Amiya Feb 25 '17 at 05:51
  • Both don't show how to get the 2 decimal places AND significant figure – user1406186 Feb 25 '17 at 06:09
  • Why do you want to round twice? This can give you incorrect results. 3.496 is closer to 3 than to 4, but if you round 3.496 to two decimal places, you get 3.5, which will round to 4, which probably is not what you want, unless you have a real good explanation. – ajb Feb 25 '17 at 06:14
  • Under the legislative document i'm working with, it requires that step by step process, so unfortunately no real room to change it. – user1406186 Feb 25 '17 at 06:29

1 Answers1

0

You can do something like this using a class in android DecimalFormat.

private String formatMagnitude(double magnitude) 
{
    DecimalFormat magnitudeFormat = new DecimalFormat("0.00");
    return magnitudeFormat.format(magnitude);
}
Rishabh Sharma
  • 270
  • 5
  • 17