digitToChar
Returns the Char that represents this decimal digit. Throws an exception if this value is not in the range 0..9
.
If this value is in 0..9
, the decimal digit Char with code '0'.code + this
is returned.
Since Kotlin
1.5Samples
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
println(5.digitToChar()) // 5
println(3.digitToChar(radix = 8)) // 3
println(10.digitToChar(radix = 16)) // A
println(20.digitToChar(radix = 36)) // K
// radix argument should be in 2..36
// 0.digitToChar(radix = 1) // will fail
// 1.digitToChar(radix = 100) // will fail
// only 0 and 1 digits are valid for binary numbers
// 5.digitToChar(radix = 2) // will fail
// radix = 10 is used by default
// 10.digitToChar() // will fail
// a negative integer is not a digit in any radix
// (-1).digitToChar() // will fail
//sampleEnd
}
Returns the Char that represents this numeric digit value in the specified radix. Throws an exception if the radix is not in the range 2..36
or if this value is not in the range 0 until radix
.
If this value is less than 10
, the decimal digit Char with code '0'.code + this
is returned. Otherwise, the uppercase Latin letter with code 'A'.code + this - 10
is returned.
Since Kotlin
1.5Samples
import java.util.*
import kotlin.test.*
fun main() {
//sampleStart
println(5.digitToChar()) // 5
println(3.digitToChar(radix = 8)) // 3
println(10.digitToChar(radix = 16)) // A
println(20.digitToChar(radix = 36)) // K
// radix argument should be in 2..36
// 0.digitToChar(radix = 1) // will fail
// 1.digitToChar(radix = 100) // will fail
// only 0 and 1 digits are valid for binary numbers
// 5.digitToChar(radix = 2) // will fail
// radix = 10 is used by default
// 10.digitToChar() // will fail
// a negative integer is not a digit in any radix
// (-1).digitToChar() // will fail
//sampleEnd
}