We can convert int value to Double object by instantiating Double class or calling Double. valueOf() method.
In Java, String. format() is a new alternative method that can be used for converting an Integer to a String object. Though the purpose of this method is to format a string, it can also be used for conversion.
Use String.valueOf():
int sdRate=5;
//text_Rate is a TextView
text_Rate.setText(String.valueOf(sdRate)); //no more errors
Use the Integer
class' static toString()
method.
int sdRate=5;
text_Rate.setText(Integer.toString(sdRate));
You can use
text_Rate.setText(""+sdRate);
Did you try:
text_Rate.setText(String.valueOf(sdRate));
You have two options:
1) Using String.valueOf() method:
int sdRate=5;
text_Rate.setText(String.valueOf(sdRate)); //faster!, recommended! :)
2) adding an empty string:
int sdRate=5;
text_Rate.setText("" + sdRate));
Casting is not an option, will throw a ClassCastException
int sdRate=5;
text_Rate.setText(String.valueOf((String)sdRate)); //EXCEPTION!
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