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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:58:36+00:00 2026-06-09T04:58:36+00:00

I got this problem with double (decimals). When a double = 1.234567 Then I

  • 0

I got this problem with double (decimals).
When a double = 1.234567 Then I use String.format("%.3f", myString);
So the result is 1.234

But when my double is 10
The result will be 10,000
I want this to be 10

Is their a way to say that he only needs to show the decimals when it is “usefull”?

I saw some posts about this, but that was php or c#, couldn’t find something for android/java about this (maybe I don’t look good).

Hope you guys can help me out with this.

Edit, for now I use something like this: myString.replace(",000", "");
But I think their is a more “friendly” code for this.

  • 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-09T04:58:38+00:00Added an answer on June 9, 2026 at 4:58 am

    The DecimalFormat with the # parameter is the way to go:

    public static void main(String[] args) {
    
            double d1 = 1.234567;
            double d2 = 2;
            NumberFormat nf = new DecimalFormat("##.###");
            System.out.println(nf.format(d1));
            System.out.println(nf.format(d2));
        }
    

    Will result in

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

Sidebar

Related Questions

Ive got this problem: Line 20 (LOOT_FromContainer(container) I need that to use as Invoke
I got a small problem . I have this date format from .net json
I got this problem after deploying my web package to IIS: HTTP Error 500.19
I got this problem with AVAudioRecorder not working for me, at least from what
I've got this problem for a while now and I cannot find a solution
ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes
Isn't Makefile syntax is target: require_files cmd... Why I got this problem? Makefile MXMLC
I’ve got this strange problem whereby the content within a scroll viewer increases in
I've got this odd problem with jQuery. I'm trying to let the change of
I got stuck in this problem for an hour. I am thinking this is

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.