0

I have this extension-function:

fun Int.convertToTextual(): String =
    when {
        (this > 337.5) -> "N"
        (this > 292.5) -> "N-W"
        (this > 247.5) -> "W"
        (this > 202.5) -> "S-W"
        (this > 157.5) -> "S"
        (this > 122.5) -> "S-E"
        (this > 67.5) -> "E"
        (this > 22.5) -> "N-E"
        else -> "N"
    }

I need it to return my strings from resources instead of just strings. How can i do it? getString doesn't work :(

Dante313
  • 161
  • 1
  • 14

1 Answers1

1

Please change Int to Double. Because You need to set an extension function for a decimal number.

fun Double.convertToTextual(context:Context): String =
    when {
        (this > 337.5) -> context.getString(R.string.code)
        (this > 292.5) -> "N-W"
        (this > 247.5) -> "W"
        (this > 202.5) -> "S-W"
        (this > 157.5) -> "S"
        (this > 122.5) -> "S-E"
        (this > 67.5) -> "E"
        (this > 22.5) -> "N-E"
        else -> "N"
    }
Arda Kazancı
  • 8,341
  • 4
  • 28
  • 50