3 Replies Latest reply: Jan 19, 2011 11:42 PM by 796440 RSS

    NumberFormat pattern issue

    793326
      Hi,

      I have to format the number in "##,##,##,###" pattern. I have coded the following code to apply the pattern. Bellow code giving the output as 123,456,789

      As per the applied format output should be 12,34,56,789.
      Please help me to resolve the issue.

              NumberFormat nf = NumberFormat.getNumberInstance();
              DecimalFormat df = (DecimalFormat)nf;
              df.applyPattern("##,##,##,###");
              String output = df.format(123456789);
        • 1. Re: NumberFormat pattern issue
          796440
          user13331987 wrote:
          As per the applied format output should be 12,34,56,789.
          Nope. That's a bogus assumption on your part. There's nothing in the docs that says that you can control how many digits go between the thousands separator. It's doing exactly what it's supposed to do.
          • 2. Re: NumberFormat pattern issue
            793326
            Thanks for quick response.

            Please let me know the work around to to format the number in "##,##,##,###" pattern.
            • 3. Re: NumberFormat pattern issue
              796440
              There's no "workaround" because this is not a bug. There's nothing that needs to be worked around. It's simply a problem you wish to solve that doesn't have a direct solution already implemented in the core API. So you write a method that implements the same logic you'd use to do it by hand, just like you would for any other such problem.