Using String.format() string in a toast Android

Viewed 8819

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();
4 Answers
Related