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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:51:09+00:00 2026-05-18T20:51:09+00:00

Ok so i am bulding this application that calculates 3 input boxes. i am

  • 0

Ok so i am bulding this application that calculates 3 input boxes. i am getting a NaN when doing some calculations with 0 values.
here is the main.xml

<?xml version="1.0" encoding="utf-8"?>


<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="@+id/ScrollView01" >




<AbsoluteLayout android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">



    <EditText android:id="@+id/InputNumber01"
        android:numeric="integer|decimal" android:imeOptions="actionNext"
        android:textStyle="bold" android:hint="Service Call"
        android:layout_x="5dip" android:layout_y="5px" android:layout_height="55dip"
        android:textSize="20dip" android:layout_width="195dip"
        android:selectAllOnFocus="true" android:inputType="numberDecimal"/>



    <EditText android:id="@+id/InputNumber02"
        android:numeric="integer|decimal" android:inputType="numberDecimal"
        android:textStyle="bold" android:hint="Parts" android:layout_x="5dip"
        android:layout_y="90px" android:layout_height="55dip"
        android:textSize="20dip" android:layout_width="195dip"
        android:selectAllOnFocus="true" android:imeOptions="actionNext"/>



    <EditText android:id="@+id/InputNumber03" android:numeric="integer|decimal"
        android:inputType="numberDecimal" android:textStyle="bold"
        android:hint="Labor" android:layout_x="5dip" android:layout_y="175px"
        android:layout_height="55dip" android:textSize="20dip"
        android:layout_width="195dip" android:selectAllOnFocus="true"
        android:imeOptions="actionDone"/>

    <Button android:text="Calculate" android:id="@+id/actionButton"

        android:textStyle="bold" android:layout_height="50dip"
        android:layout_width="fill_parent" android:layout_y="300px"
        android:textSize="15dip" />


    <TextView android:id="@+id/TextResult" android:layout_height="wrap_content"
        android:numeric="integer|decimal" android:textStyle="bold"
        android:layout_width="85dip" android:layout_x="225dip"
        android:layout_y="175dip" android:gravity="left" android:textSize="18dip"
        android:textColor="#1d9ee2" />



    <TextView android:layout_height="wrap_content" android:id="@+id/TextView04"
        android:text="Total:" android:textStyle="bold" android:gravity="right"
        android:layout_width="55dip" android:layout_y="175dip"
        android:layout_x="165dip" android:textSize="18dip" />

    <TextView android:layout_height="wrap_content" android:id="@+id/TextView05"
        android:text="Total Labor:" android:layout_y="260dip"
        android:layout_width="95dip" android:layout_x="5dip" android:gravity="right" />

    <TextView android:text="@+id/TotalLabor"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:id="@+id/TotalLabor" android:layout_y="260dip"
        android:layout_x="110dip" />

    <TextView android:layout_height="wrap_content" android:id="@+id/TextView06"
        android:layout_x="5dip" android:text="Total Services:"
        android:layout_y="280dip" android:layout_width="95dip"
        android:gravity="right" />

    <TextView android:layout_height="wrap_content"
        android:layout_width="wrap_content" android:id="@+id/TotalServices"
        android:text="@+id/TotalServices" android:layout_y="280dip"
        android:layout_x="110dip" />

    <TextView android:id="@+id/TextView07" android:text="SC Tax %:"
        android:layout_y="300dip" android:layout_height="wrap_content"
        android:layout_x="5dip" android:layout_width="95dip" android:gravity="right" />

    <TextView android:text="@+id/TextView08"
        android:layout_height="wrap_content" android:layout_width="wrap_content"
        android:id="@+id/SCTaxPercent" android:layout_y="300dip"
        android:layout_x="110dip" />

    <TextView android:layout_height="wrap_content" android:id="@+id/TextView08"
        android:text="Sales Tax:" android:textStyle="bold" android:layout_y="175dip"
        android:layout_x="5dip" android:textSize="18dip"
        android:layout_width="wrap_content" android:gravity="right" />

    <TextView android:layout_height="wrap_content" android:id="@+id/SalesTax"
        android:textStyle="bold" android:numeric="integer|decimal"
        android:layout_y="175dip" android:gravity="left"
        android:layout_width="65dip" android:textSize="18dip"
        android:layout_x="100dip" />

    <TextView android:layout_height="wrap_content" android:id="@+id/TextView09"
        android:text="SC Taxable:" android:layout_y="320dip"
        android:layout_x="5dip" android:layout_width="95dip" android:gravity="right" />

    <TextView android:layout_height="wrap_content" android:text="@+id/TextView10"
        android:layout_width="wrap_content" android:id="@+id/ScTaxable"
        android:layout_y="320dip" android:layout_x="110dip" />

    <TextView android:layout_height="wrap_content" android:id="@+id/TextView10"
        android:text="Taxable:" android:layout_y="340dip"
        android:layout_width="95dip" android:layout_x="5dip" android:gravity="right" />

    <TextView android:layout_height="wrap_content" android:text="@+id/TextView11"
        android:layout_width="wrap_content" android:id="@+id/Taxable"
        android:layout_y="340dip" android:layout_x="110dip" />

    <EditText android:layout_height="wrap_content" android:text="9.50"
        android:layout_width="90dip" android:id="@+id/SalesTaxValue"
        android:layout_x="5dip" android:layout_y="430dip" android:numeric="integer|decimal"
        android:selectAllOnFocus="true" />

    <TextView android:layout_height="wrap_content" android:id="@+id/TextView01"
        android:layout_width="wrap_content" android:layout_x="5dip"
        android:text="Sales Tax Value:" android:layout_y="407dip" />
</AbsoluteLayout>
</ScrollView>

and this is the calculator.java

package com.Eddie.TaxCalculator;

import java.text.NumberFormat;

import com.Eddie.TaxCalculator.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Calculator extends Activity {
    private Button calculateButton;
    private EditText inputField01;
    private EditText inputField02;
    private EditText inputField03;
    private EditText salesTaxValue;
    private double serviceCall;
    private double parts;
    private double labor;
    private double salestaxvalue;


String zero ="0";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        calculateButton = (Button) findViewById(R.id.actionButton);
        calculateButton.setOnClickListener(doSomethingNow);
        this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

        }

    private OnClickListener doSomethingNow = new OnClickListener() {
        public void onClick(View arg0) {
            inputField01 = (EditText) findViewById(R.id.InputNumber01);
            inputField02 = (EditText) findViewById(R.id.InputNumber02);
            inputField03 = (EditText) findViewById(R.id.InputNumber03);
            salesTaxValue = (EditText) findViewById(R.id.SalesTaxValue);


            if (inputField01.getText().toString().length()==0)
                    {
                       inputField01.setText(zero);
                    Toast toast = Toast.makeText(getApplicationContext(), 
                            "Service Call TextBox was empty.",
                            Toast.LENGTH_LONG);
                    toast.show();
                    }       
            if(inputField02.getText().toString().length()==0)
                    {
                       inputField02.setText(zero);
                    Toast toast = Toast.makeText(getApplicationContext(), 
                            "Parts TextBox was empty.",
                            Toast.LENGTH_LONG);
                    toast.show();
                    }   
            if(inputField03.getText().toString().length()==0)
                    {
                       inputField03.setText(zero);
                    Toast toast = Toast.makeText(getApplicationContext(), 
                            "Labor TextBox was empty.",
                            Toast.LENGTH_LONG);
                    toast.show();
                    }
            //service Call is 0
            if (inputField01.getText().toString().equals("0"))
            {
            Toast toast = Toast.makeText(getApplicationContext(), 
                    "Service Call TextBox value is 0.",
                    Toast.LENGTH_SHORT);
            //toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
            toast.show();
            }       
            //Parts is 0
                if (inputField02.getText().toString().equals("0"))
            {
               //inputField01.setText("10");
            Toast toast = Toast.makeText(getApplicationContext(), 
                    "Parts TextBox value is 0.",
                    Toast.LENGTH_SHORT);
            toast.show();
            }   
            //Labor is 0
            if (inputField03.getText().toString().equals("0"))
            {
               //inputField01.setText("10");
            Toast toast = Toast.makeText(getApplicationContext(), 
                    "Labor TextBox value is 0.",
                    Toast.LENGTH_SHORT);
            toast.show();
            }   


            serviceCall = Double.parseDouble(inputField01.getText().toString());
            parts = Double.parseDouble(inputField02.getText().toString());
            labor = Double.parseDouble(inputField03.getText().toString());
            salestaxvalue = Double.parseDouble(salesTaxValue.getText().toString());

            NumberFormat numberFormat = NumberFormat.getInstance();
            numberFormat.setMaximumFractionDigits(2);            
            numberFormat.setGroupingUsed(false); 



            TextView totalLabor = (TextView)findViewById(R.id.TotalLabor);
            Double totalLaborResults =  serviceCall +  labor;
            String totalLaborCalcInt = numberFormat.format(totalLaborResults).toString();
            totalLabor.setText (totalLaborCalcInt);

            TextView totalServices = (TextView)findViewById(R.id.TotalServices);
            Double totalServicesResults = (parts + labor);
            String totalServicesCalcInt = numberFormat.format(totalServicesResults);
            totalServices.setText (totalServicesCalcInt);


            TextView servicecallTaxpercent = (TextView)findViewById(R.id.SCTaxPercent);
            Double scTaxPercentResults =  (parts / totalServicesResults);
            String serviceCallPercentCalcInt =  numberFormat.format(scTaxPercentResults).toString();
            servicecallTaxpercent.setText (serviceCallPercentCalcInt);

            TextView scTaxable = (TextView)findViewById(R.id.ScTaxable);
            Double scTaxableResults = (serviceCall * scTaxPercentResults);
            String serviceCallTaxableCalcInt =numberFormat.format (scTaxableResults).toString();
            scTaxable.setText (serviceCallTaxableCalcInt);

            TextView taxable = (TextView)findViewById(R.id.Taxable);
            Double taxableResults = (parts + scTaxableResults);             
            String taxableCalcInt =numberFormat.format (taxableResults).toString();
            taxable.setText (taxableCalcInt);

            TextView salesTax = (TextView)findViewById(R.id.SalesTax);
            Double salesTaxResults = (taxableResults * salestaxvalue) /100;
            String salesTaxCalcInt = numberFormat.format (salesTaxResults).toString();
            salesTax.setText (salesTaxCalcInt);

            TextView textResult = (TextView)findViewById(R.id.Total);
            Double additionResults = (salesTaxResults + parts+ serviceCall +  labor);
            String TotalCalcInt = numberFormat.format(additionResults).toString();
            textResult.setText (TotalCalcInt);

                }

    };

};

when entering a number in input 1 (service Call) and zeros in the two other inputs i get a NaN Total.

if All input Boxes are zero value i also get a NaN total, NaN sale Tax, NaN scTax % textview (sc is short of Service Call)
NaN scTaxable, NaN taxable.

could anyone help me find this but i’ve been trying for two weeks now.
pls help.

  • 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-18T20:51:10+00:00Added an answer on May 18, 2026 at 8:51 pm

    If parts is 0 and labor is 0 then totalServicesResults is 0 and scTaxPercentsResults is infinite.

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

Sidebar

Related Questions

I have an application that uses the .NET framework 3.5. I am building this
I am building a C++ application that uses Intel's IPP library. This library is
Ok, this is downright bizarre. I am building a web application that relies on
How do you go about building a complete keyboard-accessible web application? Assuming that this
I am building an application using OpenCV that uses the webcam and runs some
I'm building this iPhone application to connect to a secured TFS server (one that
I'm building a Zend-based Web app that will permit third-party extensions. Essentially, this application's
I have this java swing application that I intend to sell over the internet.
I am building a WinForms application that interacts with a running application. This application
I am building an application that performs a master query with many joins. This

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.