I am trying to figure out how to input a formatted string to use in a toast. The toast works with a plain old string, such as
string s1 = "You scored"
But it will not work with String.format(). Why is this? Is there any way to work around this? I already know it will work if I do
Toast.makeText(this, "You scored: " + score + "%", Toast.LENGTH_LONG).show();
But I want the percentage to not have any decimal numbers. I have searched around but could not find an answer.
This is what doesn't work:
float score = ((float) mNumberCorrect / 6)*100;
Toast.makeText(this, String.format("You scored: %d", score) , Toast.LENGTH_LONG).show();
you have to write %f in place of %d like below.
float score = ((float) mNumberCorrect / 6)*100;
Toast.makeText(this, String.format("You scored: %f", score) , Toast.LENGTH_LONG).show();
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