https://kotlinlang.org logo
#getting-started
Title
# getting-started
m

Moritz Post

11/29/2021, 10:45 AM
Is there a kotlin only replacement for the java method
Character.getNumericValue()
? It would be useful in kmp but i can't seem to find one.
j

Joffrey

11/29/2021, 10:47 AM
Depends on what you need. There is Char.digitToInt but it doesn't handle roman numerals like
\u216C
, while Java's method does. If you only need digits in the
0-9
range (or
a-z
range in bases > 10), then
digitToInt
should be enough
m

Moritz Post

11/29/2021, 10:55 AM
digitToInt
works for numbers only. the getNumericValues actually returns the full width number for A-Z which i am looking for. so
A
is
10
etc...
t

Ties

11/29/2021, 11:30 AM
A colleague of mine wrote a blogpost about this: https://blog.jdriven.com/2019/10/converting-char-to-int-in-kotlin/
m

Moritz Post

11/29/2021, 11:32 AM
thanks. i actually found this blog post but it describes to use getNumericValues which i can not use in KMP
for a simple solution i mapped the chars manually to the supported range in need
t

Ties

11/29/2021, 11:35 AM
My apologies then 🙂 happy you found a solution!
m

Moritz Post

11/29/2021, 11:38 AM
no worries. thanks for chipping in. maybe your colleague finds a better solution for KMP as well ;)
i

ilya.gorbunov

11/29/2021, 12:39 PM
digitToInt  works for numbers only. the getNumericValues actually returns the full width number for A-Z which i am looking for. so A is 10 etc...
You need to specify
radix
parameter > 10 to work with digits A-Z.
3 Views