Hey! I am trying to cast a Boolean to String (true...
# getting-started
c
Hey! I am trying to cast a Boolean to String (true -> "1" | false -> "0"). This is because the API I am talking to uses 1 and 0. Is there a better way to do that than the method I am using?
Copy code
val boolToString = if (boolean) "1" else "0"
h
how about something like
Copy code
fun Boolean.toBinary() = if (this) "1" else "0"
👍 2
c
As an extension, you mean ? cool idea 🙂
h
yes 🙂
c
It's done, thanks for the idea! 👍