0

I have a Float that I'd like to format as a percentage. If it was C# then it would be f.ToString("P1"). However, as far as I can tell, this is not possible in Kotlin.

The documentation is woefully inadeuate:

So do you all have to write your own number formatting code?

Richard Barraclough
  • 2,625
  • 3
  • 36
  • 54
  • 2
    You're running code on the JVM. The whole JDK, and all its documentation, is available to you. See https://stackoverflow.com/questions/26954443/how-do-i-format-my-percent-variable-to-2-decimal-places for examples. – JB Nizet Aug 11 '19 at 11:59
  • No, it's not Java, it's Kotlin. Does Kotlin have documentation for string formatting? – Richard Barraclough Sep 02 '19 at 15:08
  • Kotlin is interoperable with Java. If you run your code on the JVM (as your links to the jvm documentation pages of Kotlin seem to indicate), you can use any class of the JDK. Do you understand that? – JB Nizet Sep 02 '19 at 16:48

0 Answers0