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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:49:34+00:00 2026-06-11T01:49:34+00:00

I am working on an android calculator. the user is pressing the buttons for

  • 0

I am working on an android calculator. the user is pressing the buttons for 1 to 9 and decimal dot, and then inputnum (arraylist ) would then parse the display as input, and then oepration and then display the answer. The related codes as follows:

ArrayList<Double> inputnum = new ArrayList<Double>(); 
double inputnum1; 
double inputnum2;    

...


inputnum.add(Double.parseDouble(Fakedisplay.getText().toString()));        
case SUBTRACT: 
        inputnum1 = inputnum.get(0); 
        inputnum2 = inputnum.get(1); 
        inputnum.removeAll(inputnum); 
        inputnum.add(inputnum1 - inputnum2); 

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

        String strf2=Fakedisplay.getText().toString(); 
        String strippedf2 = Double.valueOf(strf2).toString();  
        if (strippedf2.endsWith(".0")) 
            strippedf2 = strippedf2.substring(0, strippedf2.length() - 2); 
        Fakedisplay.setText(strippedf2); 

Problem:
For 1000.84 – 1000.01 it will gives 0.830000000000041, which is not desired for the presentation,
Yet this problem just only occur for subtraction, exactly the same codings for add, multiply and division but work very well, ie: 1000.84+ 1000.01 presenting 2000.85 and no more, 1000.84*1000.01=1000850.0084 and no more, 1000.84/1000.01 also works and present correctly.

Why is it so special for subtraction? how to handle it?

  • 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-11T01:49:36+00:00Added an answer on June 11, 2026 at 1:49 am

    Try Decimal Format to Show long value upto N Decimal Digit.

    DecimalFormat round = new DecimalFormat ("###.##");
    String output = round.format(inputnum.get(0));
    Fakedisplay.setText(output); 
    

    Output = 0.83 for 0.830000000000041

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

Sidebar

Related Questions

I am working on a calculator application for Android. I was wondering what the
I've been working on an Android calculator for the past several days. I've reached
I am now working on an android calculator and have some problems on displaying
i am working on android and trying to read a value from my preference
I am currently working on android project where I am using a custom list
I am working on Android Application. Now I have requirement of search the entered
I am currently working on android project where I want to have a text
I am working on android applications. I created two pages i.e Page1 and Page2.
I'm working with Android and I really need a fast way to get a
I am working in android. I designed a video player in my application. Most

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.