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

  • Home
  • SEARCH
  • 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 7880007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:02:27+00:00 2026-06-03T04:02:27+00:00

How can I use NumberFormat to format a double value for a given Locale

  • 0

How can I use NumberFormat to format a double value for a given Locale (default locale is sufficient) and for a given number of decimal places?

For example, I have these values:

double d1 = 123456.78;
double d2 = 567890;

And I want to print them in the following way, for example with US locale and 2 decimal places:

123,456.78
567,890.00

I don’t actually care about rounding mode in this case, because these double values are gained from a BigDecimal with the given scale, so their number of decimal places is always lesser or equal than the number of decimal places I want to print.

Edit:

To make things a bit more clear, the thing is that I want to display money in a locale dependent way, but with a fixed number of decimal places. The example above showed, how the values should be formatted if the system locale is en_US. Now lets say, the system locale is cs_CZ (Czech), so the same numbers should be formatted in this way:

123 456,78
567 890,00

Now, how can I set up a NumberFormat to always display 2 decimal places, but to display thousands separator and decimal point based on the current locale?

  • 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-03T04:02:29+00:00Added an answer on June 3, 2026 at 4:02 am

    If you care to read NumberFormat’s documentation, the solution would be obvious:

    double d1 = 123456.78;
    double d2 = 567890;
    // self commenting issue, the code is easier to understand
    Locale fmtLocale = Locale.getDefault(Category.FORMAT);
    NumberFormat formatter = NumberFormat.getInstance(fmtLocale);
    formatter.setMaximumFractionDigits(2);
    formatter.setMinimumFractionDigits(2);
    System.out.println(formatter.format(d1));
    System.out.println(formatter.format(d2));
    System.out.println(fmtLocale.toLanguageTag());
    

    On my machine this prints out:

    123 456,78
    567 890,00
    pl-PL

    I believe this is what you are looking for, and you don’t have to mess-up with patterns. I wouldn’t do that – for instance there are locales which group digits by two, not by three (this is the reason we talk about grouping separator and not thousands separator).

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

Sidebar

Related Questions

I want to use number_format function in PHP. For example: $number = 234.51; echo
I have a variable $totalprice with number 1,072.00. If I use int($totalprice) or number_format($totalprice),
In most case, how can we justify, when shall we use NumberFormat.getInstance(); When shall
I'm working with NumberField and NumberFormat. How can I change NumberConstants.decimalSeparator() value without changing
how can use JS variable in PHP like this ? <script> x = document.getElementById(1).value;
I can use FireFox and FireBug, in a pane, I can open a .css
I can use the PRINT statement in a stored procedure to debug my code.
I can use stat() to figure out what permissions the owner, group, or others
We can use solr range query like: http://localhost:8983/solr/select?q=queryStr&fq=x:[10 TO 100] AND y:[20 TO 300]
You can use the Filter property of a BindingSource to do SQL like filtering.

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.