-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.

Casper Spruit
  • 924
  • 1
  • 14
  • 31
Daniel
  • 39
  • 1
  • 7

1 Answers1

2

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

Nitesh
  • 3,760
  • 1
  • 19
  • 25
  • no, that does not work, it shows ".1f" as the text. nvm, I realize what you meant, thanks, it works :) – Daniel Dec 06 '16 at 10:27
  • Happy to help :) .. Here on SO we mark the answer as right which solves the problem. – Nitesh Dec 06 '16 at 11:11