mastodon.zunda.ninja is one of the many independent Mastodon servers you can use to participate in the fediverse.
Zundon is a single user instance as home of @zundan as well as a test bed for changes of the code.

Administered by:

Server stats:

1
active users

そういえばことりんちゃんは "".toDouble() とかで例外投げてくれるし油断できない←

@zundan toDoubleOrNull()があるし、kotlinとJavaの境界さえ跨がなければnullチェックは自動で行われますよ

zunda

@tateisu ってやっと調べてみたらtoDoubleOrNull()はNull安全なのではなくて、数字ではない場合にnullを返すのですね。勘違いしてました…。失礼しました。
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-double-or-null.html

KotlintoDoubleOrNull - Kotlin Programming Language

@zundan Regexを通さずに最初からtoDoubleOrNull()でパースすると、Double.valueOf()が受け入れる記法を全て使えるようになります

@tateisu なるほど~。今回は、ユーザーが入力するのは整数か小数点以下多くて2桁くらいまでで、数字キーボードにも有る空白などをタイポしちゃわないようにRegexを通してます