Here is my simple code
@Override
public void onClick(View v) {
try {
double price = Double.parseDouble(ePrice.getText().toString());
double percent = Double.parseDouble(ePercent.getText().toString());
double priceValue = price * percent/100.0f;
double percentValue = price - priceValue;
moneyToGet.setText(String.valueOf(priceValue));
moneyToPay.setText(String.valueOf(percentValue));
moneyToGet.setText("" + priceValue);
moneyToPay.setText("" + percentValue);
// catch
} catch (NumberFormatException ex) {
// write a message to users
moneyToGet.setText("");
}
}
});
This is a simple code for Percentage Calculator.
What I want is to avoid the Scientific Notation in my Calculator cause I don't want to explain to user what is Scientific Notation.
For example if I want to calculate 100,000,000 and cut 50% of it, it Should give me 50,000,000 which is giving me 5.0E7 And in my case this doesn't make any sense to the user. And of course I know both results are correct. Thanks in Advance.
(1) Right-click a cell where you want to remove scientific notation, and (2) choose Format Cells… 2. In the Format Cells window, (1) select the Number category, (2) set the number of decimal places to 0, and (3) click OK.
Just to add to what Joachim said, you can't "remove E from a double" because double doesn't have E. Double is just a binary number. It is up to the formater to display that number with E or not.
double dexp = 12345678; System. out. println("dexp: "+dexp);
To convert any number into scientific notation, you write the non-zero digits, placing a decimal after the first non-zero digit. Then, you count the number of digits you need to move the beginning decimal to get to where your decimal is now. If you move the decimal to the left, then your power is positive.
Check answer here. You can write
moneyToGet.setText(String.format("%.0f", priceValue));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With