Reputation: 99
I have a Unit Converter. When I enter a value of 10000000 Celsius to convert to Fahrenheit, I get the answer 1.8000032E7. Its the correct answer but how do I make the app display 180000320 instead of 1.8000032E7 ??
Here's part of my Java code.
celsiusET.addTextChangedListener(new TextWatcher() {
double in,out;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!machineChange) {
machineChange = true;
if(s.toString().equals("-")) {
kelvinET.setText("");
fahrenheitET.setText("");
}
else if(s.toString().equals(".")) {
kelvinET.setText("");
fahrenheitET.setText("");
}
else if(!s.toString().equals("")) {
in = Double.parseDouble(s.toString());
out = ((in*9)/5)+32;
fahrenheitET.setText(String.valueOf(out));
out = in+273.15;
kelvinET.setText(String.valueOf(out));
}
else {
kelvinET.setText("");
fahrenheitET.setText("");
}
machineChange = false;
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
Upvotes: 0
Views: 52
Reputation: 47
private DecimalFormat formatter;
formatter = new DecimalFormat("#,##,##,###");
act_income_basic_sal_etxt.setText(formatter.format((int)myApplication.getTaxCalculationModel().getA3()));
Specify your format in DecimalFormat and you will get your number as you want.
Upvotes: 1
Reputation: 35234
DecimalFormat
can do that for you.
DecimalFormat is a concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features designed to make it possible to parse and format numbers in any locale, including support for Western, Arabic, and Indic digits. It also supports different kinds of numbers, including integers (123), fixed-point numbers (123.4), scientific notation (1.23E4), percentages (12%), and currency amounts ($123). All of these can be localized.
Upvotes: 0