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 8597499
In Process

The Archive Base Latest Questions

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

Currently, using DecimalFormat I would like to show maximum number of decimal places, or

  • 0

Currently, using DecimalFormat I would like to show maximum number of decimal places, or don’t show at all. For instance,

  1. 100.0 shown as “100”
  2. 100.123 shown as “100.123”
  3. 100.123456789012345 shown as “100.123456789012345”
    Using format as

new DecimalFormat("0.###"); is partially correct. It works for 1st case, 2nd case but not 3rd case. As, I have no idea how much # should I have?

So, may I know what is the correct DecimalFormat I should use?

  • 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-12T00:55:39+00:00Added an answer on June 12, 2026 at 12:55 am

    You can use setMaximumFractionDigits() to do this. The maximum value is 340, so might as well set it to that value:

    public static void main(String[] args) {
        DecimalFormat formatter = new DecimalFormat();
        formatter.setMaximumFractionDigits(340);
        BigDecimal[] numbers = {new BigDecimal("100.0"), new BigDecimal("100.123"), new BigDecimal("100.123456789012345")};
        for (BigDecimal number : numbers) {         
            System.out.println(formatter.format(number));
        }
    }
    

    prints

    100
    100.123
    100.123456789012345
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im currently using a plugin called Cycle for jQuery and would like to tweak
I am currently using matplotlib.pyplot to create graphs and would like to have the
Im currently using a UITableView like any other, and I am researching into the
i want to show only two decimal places in my edit text, ofc i
Currently using Telerik ASP .NET MVC Controls version 2011.2.712 Hello all, I am trying
Im currently using jquery to link all td's to the edit link but i
Im currently using worpress to publish/upload images and show them on an iphone application.
Im currently using base64_encode for some $_GET params that i don't want regular user
I am using DecimalFormat to create a formated decimal that is always 6 characters
I'm currently using http://benalman.com/projects/jquery-hashchange-plugin/ and I noticed that my hashes show up as /#page

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.