java - Rounding to one decimal place -
I am currently working on a temprature converter app. Everything works but I get more than 5 decimal And I have tried to look at it and search on Google, but I do not know how this place is where I display text in main.java:
text = (EditText) findViewById (R.id.editText1); Result = (TextView) findViewById (R.id.tvResult); Float input value = float. Perfotto (text .gettext () .toString ()); Decimalable df = new decimal time ("# 00."); String s = (String.valueOf (Convert Farrals. Convert CelsiumFofrenheit (Inputville)); String D = (string.valuef (convertphorrals. ConvertFrennetTellousus (inputwolves)); If (Celsius button. (Czech)) {Results. System Text (D); CelsiusButton.setChecked (wrong); Fahrenheitbutton.setChecked (true); } And (result.set text (s); fahrenheitButton.setChecked (wrong); celsiusButton.setChecked (true);}
And here's where I count it:
// Celsius converts to Public Static Float Convert Fearhen Heatoconcealus (Float Fahrenheit) (Returns (Fahrenheit 32) * 5/9);} Converts Fahrenheit to a Public Static Float Convert Celsius Tofernath (float Celsius) {returns (Celsius * 9) / 5) + 32; }
Your code here indicates that it is producing decimal format to work But, you really do not use it!
decimalf df = new decimal time ("# 00."); String s = (String.valueOf (Convert Farrals. Convert CelsiumFofrenheit (Inputville)); String D = (string.valuef (convertphorrals. ConvertFrennetTelius (inputwolves));
The code should be:
decimalf df = new substitution ("# 00."); String s = df.format (Convert Farrals. Convert CelsioFrohnhite (Inputville)); String D = df.format (convertor seals. ConvertFranNitTotales (inputwolves));
It is now more common in Java to use instead of decimal format. Consider:
string s = string.format ("% .ff", convertor seals. Convert cells to sophisticated (inputwolves)); In the end, your question indicates that you want 1 decimal place, but, the decimal format you use is called two.
Comments
Post a Comment