Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin.text › to-big-decimal.html
toBigDecimal | Core API – Kotlin Programming Language
Parses the string as a java.math.BigDecimal number and returns the result.
Kotlin
kotlinlang.org › api › latest › jvm › stdlib › kotlin.text › to-big-decimal.html
toBigDecimal
Splits this char sequence into a list of strings each not exceeding the given size. ... Splits this char sequence into several char sequences each not exceeding the given size and applies the given transform function to an each.
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin.text › to-big-decimal-or-null.html
toBigDecimalOrNull | Core API – Kotlin Programming Language
kotlin-stdlib/kotlin.text/toBigDecimalOrNull · JVM · fun String.toBigDecimalOrNull(): BigDecimal?(source) Parses the string as a java.math.BigDecimal number and returns the result or null if the string is not a valid representation of a number.
How do I round a BigDecimal to 2 decimal places in Kotlin?
Call value.setScale(2, RoundingMode.HALF_UP), or HALF_EVEN for banker's rounding.
mojoauth.com
mojoauth.com › dev guides › kotlin bigdecimal: precise decimal math
Kotlin BigDecimal: Precise Decimal Math | MojoAuth Dev Guides
Why does 10 / 3 return 3 with BigDecimal in Kotlin?
Kotlin's / keeps the dividend's scale, and BigDecimal("10") has scale 0. Use a.divide(b, 2, RoundingMode.HALF_UP) to get 3.33.
mojoauth.com
mojoauth.com › dev guides › kotlin bigdecimal: precise decimal math
Kotlin BigDecimal: Precise Decimal Math | MojoAuth Dev Guides
Does Kotlin have a decimal type?
Not a built-in primitive. On the JVM, Kotlin uses java.math.BigDecimal, with operator overloads and toBigDecimal() extensions from the standard library.
mojoauth.com
mojoauth.com › dev guides › kotlin bigdecimal: precise decimal math
Kotlin BigDecimal: Precise Decimal Math | MojoAuth Dev Guides
Android Developers
developer.android.com › api reference › bigdecimal
BigDecimal | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
Kotlin
kotlinlang.org › api › latest › jvm › stdlib › kotlin › java.math.-big-integer › to-big-decimal.html
toBigDecimal - Kotlin Programming Language
Returns the value of this BigInteger number as a BigDecimal scaled according to the specified scale and rounded according to the settings specified with mathContext.
Top answer 1 of 8
185
The BigDecimal(double) constructor can have unpredictable behaviors. It is preferable to use BigDecimal(String) or BigDecimal.valueOf(double).
Use with AISystem.out.println(new BigDecimal(135.69)); //135.68999999999999772626324556767940521240234375
System.out.println(new BigDecimal("135.69")); // 135.69
System.out.println(new BigDecimal("13۵.۶9")); // 135.69
System.out.println(BigDecimal.valueOf(135.69)); // 135.69
The documentation for BigDecimal(double) explains in detail:
- The results of this constructor can be somewhat unpredictable. One might assume that writing new BigDecimal(0.1) in Java creates a BigDecimal which is exactly equal to 0.1 (an unscaled value of 1, with a scale of 1), but it is actually equal to 0.1000000000000000055511151231257827021181583404541015625. This is because 0.1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the value that is being passed in to the constructor is not exactly equal to 0.1, appearances notwithstanding.
- The String constructor, on the other hand, is perfectly predictable: writing new BigDecimal("0.1") creates a BigDecimal which is exactly equal to 0.1, as one would expect. Therefore, it is generally recommended that the String constructor be used in preference to this one.
- When a double must be used as a source for a BigDecimal, note that this constructor provides an exact conversion; it does not give the same result as converting the double to a String using the Double.toString(double) method and then using the BigDecimal(String) constructor. To get that result, use the static valueOf(double) method.
2 of 8
41
Use with AIString currency = "135.69";
System.out.println(new BigDecimal(currency));
//will print 135.69
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin
kotlin | Core API – Kotlin Programming Language
The String class represents character strings. All string literals in Kotlin programs, such as "abc", are implemented as instances of this class.
Starred by 475 users
Forked by 48 users
Languages: Kotlin 99.3% | Shell 0.7%
Kotlin Discussions
discuss.kotlinlang.org › language design › strange bigdecimal result
Strange BigDecimal result - Language Design - Kotlin Discussions
April 21, 2023 - Hello friends, I am a bit confused at this behavior of BigDecimal, maybe someone has insight. When I compare: java.math.BigDecimal(0) == java.math.BigDecimal(0.00) // true However, when I compare: java.math.BigDecimal(0) == (0.00).toBigDecimal() // false Why is there a difference when converting ...
GitHub
github.com › ionspin › kotlin-multiplatform-bignum › blob › main › bignum › src › commonMain › kotlin › com › ionspin › kotlin › bignum › decimal › BigDecimal.kt
kotlin-multiplatform-bignum/bignum/src/commonMain/kotlin/com/ionspin/kotlin/bignum/decimal/BigDecimal.kt at main · ionspin/kotlin-multiplatform-bignum · GitHub
* Parse BigDecimal from a supplied string.
Author: ionspin
Qlik Community
community.qlik.com › t5 › Talend-Studio › Convert-a-string-to-Big-Decimal › td-p › 2348714
Solved: Convert a string to Big Decimal - Qlik Community - 2348714
February 28, 2023 - We start by initializing a string variable `str` with the value "$6.00". We then create a `BigDecimal` object `bd` by passing the string `str` to the constructor of `BigDecimal`.
Java2Blog
java2blog.com › java-string-to-bigdecimal
Java String to BigDecimal – Java2Blog
You can simply use BigDecimal ‘s String based constructor to do it.
KT Academy
kt.academy › article › kfde-values
Basic values in Kotlin
However, there are cases where we need to have perfect precision and unlimited number size. On JVM, for unlimited number size we should use BigInteger, which represents a number without a decimal part. For unlimited size and precision, we should use the BigDecimal, which represents a number that has a decimal part.