-3

I am trying to show a percentage but how do I show % sign using string format? Here's my line of code

precent.setText(String.format(Locale.getDefault(),"%.1f", precentNum))

I mean how do I put a percentage sign at the end of the text? couldn't find an answer when I searched.

4
  • 1
    %% is the answer - and the word is percentage, not precentage. Commented Dec 6, 2016 at 10:23
  • no, then it shows ".1f" instead of the number. Commented Dec 6, 2016 at 10:25
  • Use "%.1f%%" as your format string. The %% shows up as %. Commented Dec 6, 2016 at 10:26
  • oh I thought at the start, thanks :) sorry for the ignorance. Commented Dec 6, 2016 at 10:28

1 Answer 1

2

Try %% instead of %. It will display a single % in your string.

Sign up to request clarification or add additional context in comments.

2 Comments

no, that does not work, it shows ".1f" as the text. nvm, I realize what you meant, thanks, it works :)
Happy to help :) .. Here on SO we mark the answer as right which solves the problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.