Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8629897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:55:32+00:00 2026-06-12T08:55:32+00:00

Somewhat related to this question and several other SO questions relating to formatting decimals

  • 0

Somewhat related to this question and several other SO questions relating to formatting decimals (all of which did not help me in this instance).

I am trying to format a Long into a String e.g. 123456 -> 012.345,6 (period followed by comma as strange as it may seem, it’s a project requirement).

I am experimenting with DecimalFormat for the formatting:

private static final DecimalFormat format = new DecimalFormat(“##0.000,0”);

However it throws an exception during instantiation:

java.lang.IllegalArgumentException: Malformed pattern “##0.000,0”

I have also experimented with changing the locale to an EU system beforehand e.g.

NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.GERMAN);

How can I format numbers in this way? Is DecimalFormat the wrong solution? Can I use a NumberFormat? Or will I need a custom formatter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:55:33+00:00Added an answer on June 12, 2026 at 8:55 am

    You should avoid constructing DecimalFormat directly. Commas are always used for grouping in the pattern definition, regardless of how they appear in the target locale. Similarly, periods are always used for decimals. This appears illogical, but one must remember this is a pattern definition, and like #, these characters describe a replacement, not the character itself.

    NumberFormat f = NumberFormat.getInstance(Locale.GERMANY);
    if (f instanceof DecimalFormat) {
        ((DecimalFormat) f).applyPattern("##0,000.0");
    }
    f.format(123456 / 10.0);
    

    The division by 10 is necessary to obtain a digit after the decimal point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is somewhat related to another question I've asked but I figure why not
This is somewhat related to my other question . I've been using a dll
This is somewhat related to this question , but not quite. I have two
This is somewhat related to a question I asked not too long ago today.
This question is somewhat related to my previous question (not necessary to go through
This questions is somewhat related to this question Prawn + Prawnto Issue . I've
I think this is somewhat related to this question , but being not sure
[This question is somewhat related to this question , but the answers are not...]
I found a couple of questions somewhat related to this: httpclient-request-set-attribute-question commons-httpclient-adding-query-string-parameters-to-get-post-request but I
Somewhat related to this question , but in the absence of any answer about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.