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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:16:00+00:00 2026-05-25T06:16:00+00:00

In pure Java, I would normally have a function like the one below for

  • 0

In pure Java, I would normally have a function like the one below for limiting the number of decimal places to decimalCount for a given number value. However, according to the GWT docs, “GWT does not provide full emulation for the date and number formatting classes (such as java.text.DateFormat, java.text.DecimalFormat, java.text.NumberFormat, and java.TimeFormat).” What would one do to the following function in order to make it work in GWT?

public static String getFormatted(double value, int decimalCount) { 
    DecimalFormat decimalFormat = new DecimalFormat();
    decimalFormat.setMaximumFractionDigits(decimalCount);
    return decimalFormat.format(value);
}
  • 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-05-25T06:16:01+00:00Added an answer on May 25, 2026 at 6:16 am

    Check out NumberFormat (com.google.gwt.i18n.client.NumberFormat) in the GWT Javadoc.

    I’ve never used it but I see this example in there:

    // Custom format
    value = 12345.6789;
    formatted = NumberFormat.getFormat("000000.000000").format(value);
    // prints 012345.678900 in the default locale
    GWT.log("Formatted string is" + formatted);
    

    So this should work for you.

    Update

    This method provides the same functionality as the one in your question. I went ahead and asked for the most efficient way to go about this, see that question here. (Sorry this answer has been edited so much – it was just bugging me)

    public static String getFormatted(double value, int decimalCount) {
        StringBuilder numberPattern = new StringBuilder(
                (decimalCount <= 0) ? "" : ".");
        for (int i = 0; i < decimalCount; i++) {
            numberPattern.append('0');
        }
        return NumberFormat.getFormat(numberPattern.toString()).format(value);
    }
    

    Alternatives include using a set amount of "0"’s and using substring to pull out the required pattern as @Thomas Broyer mentioned in the comments.

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

Sidebar

Related Questions

I have a pure Winapi application that needs a few new features. One of
I would like to run a Java program with garbage collection switched off. Managing
I have been searching for a pure Java SSH library to use for a
I would like to find a FREE MP4 (container) writer for Java. I do
i have a pure java project for infrastructure of automates tests. should i start
I think about using AspectJ in an existing project. I have several pure Java
For example DateTime dt=new DateTime(java.sql.Time.valueOf(00:00:00)); dt.minusMinutes(20); // this line would have no effect! The
Is there a pure-Java equivalent to <jsp:forward page=... /> that I can use within
The Situation: I'm optimizing a pure-java implementation of the LZF compression algorithm, which involves
I've used JAXB Marshaller as well as my own marshaller for marshalling pure java

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.