Is there a kotlinfied `Character.getNumericValue()...
# getting-started
k
Is there a kotlinfied
Character.getNumericValue()
?
v
like
'c'.toInt()
?
d
No,
getNumericValue
returns
5
for
"5"
👍 1
I don't think there is a Kotlin-only version, as it requires large character data tables. These are present in the JDK, but Javascript for example doesn't have an API for it.
r
You could do
char.toString().toInt()
, though it's not optimal.
d
And that also does not cover everything that
getNumericValue
does.
getNumericValue('Ⅱ')
("Roman Numeral Two") returns
2
.
r
Ah, I was not aware of that. That is a weird function.
k
Yeah there are lots of these functions in the
Character
class, but I wonder what the purpose is? Is there ever a site where you can type in digits and where Ⅱ is allowed?
Presumably if your code is going to be used in a language with a different number system you'll be using specific input forms for those symbols?
d
That's the JDK for you. You could argue that
java.time
is similarly overengineered with it's support for crazy calendar systems