1

I have to round a number to the third decimal place and display the number like this, 123.12(3). I need some help getting the parentheses around the third decimal place. Here is the code I have:

DecimalFormat reviewRound = new DecimalFormat("##0.000" );
imtheman
  • 4,360
  • 1
  • 26
  • 28

1 Answers1

1

I don't think that it is possible just with DecimalFormat. Here is a function I created to get you what you want.

public static String format(double d)
{
    DecimalFormat test = new DecimalFormat("##0.000");
    String str = test.format(d);
    String str2 = str.substring(str.length() - 1);
    str = str.substring(0, str.length() - 1);

    return str + '(' + str2 + ')';
}
imtheman
  • 4,360
  • 1
  • 26
  • 28