Note that there are some explanatory texts on larger screens.

plurals
  1. POMethod to add two values of type float and integer in Android
    text
    copied!<p>Small <code>Android</code> application, which performs <code>addition</code> and other basic operations, and the <code>OnClick()</code> is as follows</p> <pre><code>@Override public void onClick(View v) { switch (v.getId()) { case R.id.btnAdd: isValidToProcess(1); break; ...... /*Switch continues for all other operations like Subtraction,etc*/ } } </code></pre> <p>and my <code>isValidToProcess()</code> is as follows</p> <pre><code>private boolean isValidToProcess(int a) { String num1 = mEdit1.getText().toString(); String num2 = mEdit2.getText().toString(); if (num1.matches("") || num2.matches("")) { ValueEmptyWarning(); } else { float numa = Float.parseFloat(num1); float numb = Float.parseFloat(num2); switch (a) { case 1: addition(numa, numb); break; ...... /*Switch continues for all other operations like Subtraction,etc*/ } } </code></pre> <p>My <code>addition()</code> function </p> <pre><code>public void addition(float numa, float numb) { answer = numa + numb; mEdit3.setText(String.valueOf(answer)); Log.v(TAG, "Error at Subtraction"); } </code></pre> <p>This program is working fine for <code>Float</code> and <code>Integer</code> numbers, But the problem is, for both Integer and Float values the answer will be in fractions, For example <code>Number1=2</code> and <code>Number2=3</code> and the <code>answer=5.0</code> </p> <p>Objective: If User inputs Integer, The decimal point should not be there.</p> <p>Is this possible to get the type of Value which user has entered on <code>EditText</code>?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload