Created
September 20, 2022 22:27
-
-
Save s1monw1/8d4e169f16cf8de859ca26498bd9a834 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@JvmInline | |
value class ParsableNumber(val original: String) { | |
val parsed: BigDecimal | |
get() = original.toBigDecimal().setScale(2, RoundingMode.HALF_UP) | |
} | |
fun getParsableNumber(number: String): ParsableNumber { | |
return ParsableNumber(number) | |
} | |
fun main() { | |
val parsableNumber = getParsableNumber("100.12212") | |
println(parsableNumber.parsed) | |
println(parsableNumber.original) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment