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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:48:57+00:00 2026-06-10T09:48:57+00:00

I am now working on an android calculator and have some problems on displaying

  • 0

I am now working on an android calculator and have some problems on displaying the result…the display is now set using string.format rounding at 9 decimal places…but though this is true for displaying endless decimal results, many other situations are not necessary, like

1+2 should display 3 instead of 3.000000000;

2.03*3 should display 6.09 instead of 6.090000000

  1. how could i do this? ask the program to see whether the last digit is 0 and if yes, to replace by “”?
  2. how could i display “,’ for each thousand place? ie. 123,456,789 instead of solely 123456789 for both input and answer?

NEW PROBLEM ARISED!!

I newly discovered that after incorporating with the suggestions, for small figures manipulations like under 1000, the displayed answer is ok ( eg 999 * 999 probably displaying 998001). Yet If figures are over, the displayed answer become like this way, eg 9999 * 9999 = 9.998001e7. Is it related to the limitation of double? if then, how could it be solved?

the original coding is as follows:

    case MULTIPLY:                
        inputnum1 = inputnum.get(0); 
        inputnum2 = inputnum.get(1); 

        inputnum.removeAll(inputnum); 

        inputnum.add(inputnum1 * inputnum2); 

        Display.setText(String.format("%.9f", inputnum.get(0)));  
//
            String str1=Display.getText().toString();
            String stripped1 = Double.valueOf(str1).toString(); 
            Display.setText(stripped1);
//              
            break;

the updated code as follows:

    private void calculation (int operator) { 

        inputnum.add(Double.parseDouble(Display.getText().toString())); 

        if (operator != EQUALS) {nextOperation = operator;}
        else if (operator == EQUALS){nextOperation = 0;} 

        switch (currentOperation) { 
    case MULTIPLY: 
        inputnum1 = inputnum.get(0); 
        inputnum2 = inputnum.get(1); 

        inputnum.removeAll(inputnum); 

        inputnum.add(inputnum1 * inputnum2); 

        Display.setText(String.format("%.19f", inputnum.get(0)));  

        DecimalFormat myFormatter3 = new DecimalFormat("###,###,###,###,###,###.#########"); 
        String str3=Display.getText().toString(); 
        String stripped3 = Double.valueOf(str3).toString(); 
        stripped3 = myFormatter3.format(Double.valueOf(stripped3)); 
        if (stripped3.endsWith(".0")) 
            stripped3 = stripped3.substring(0, stripped3.length() - 2); 
        Display.setText(stripped3);

similar for
case SUBTRACT:
case ADD:
case DIVISION:

Many thanks!

  • 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-10T09:48:59+00:00Added an answer on June 10, 2026 at 9:48 am

    The commas are easy to add:

    public class DecimalFormatDemo {
    
    static public void customFormat(String pattern, double value ) {
      DecimalFormat myFormatter = new DecimalFormat(pattern);
      String output = myFormatter.format(value);
      System.out.println(value + "  " + pattern + "  " + output);
    }
    
    static public void main(String[] args) {
    
      customFormat("###,###.###", 123456.789);
      customFormat("###.##", 123456.789);
      customFormat("000000.000", 123.78);
      customFormat("$###,###.###", 12345.67);  
    }
    }
    

    The zeros go like this, I believe:

    DecimalFormat myFormatter = new DecimalFormat("###,###,###,###.###");
    String str1=Display.getText().toString();
    String stripped1 = Double.valueOf(str1).toString();
    stripped1 = myFormatter.format(Double.valueOf(stripped1));
    if (stripped1.endsWith(".0"))
        stripped1 = stripped1.substring(0, stripped1.length() - 2);
    Display.setText(stripped1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working in android. i have these two images:- and now using for
I have some problem. I'm working with Android 2.2 and now I want to
I am working on Android Application. Now I have requirement of search the entered
I'm working through some android tutorials right now in preparation for a two week
I have an android application and web-server working together. Now I want user log
I have been working with android for a few years now, not once have
I am working in android. i am trying to display name of university using
I am working in android, I am using a button. Now I want to
I am now working on an android app in which I need to display
I've been working with Android for just a couple of weeks now and have

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.