🌐
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.
People also ask

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 · 中文 – 简体
🌐
MojoAuth
mojoauth.com › dev guides › kotlin bigdecimal: precise decimal math
Kotlin BigDecimal: Precise Decimal Math | MojoAuth Dev Guides
September 28, 2026 - For exact decimal math in Kotlin, use java.math.BigDecimal: create values from strings with "19.99".toBigDecimal() or BigDecimal("19.99"), and use Kotlin’s operators +, -, *, / and %, which the standard library maps to BigDecimal methods.
🌐
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:

  1. 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.
  2. 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.
  3. 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.
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java string › converting string to bigdecimal in java
Converting String to BigDecimal in Java | Baeldung
June 17, 2026 - Sometimes, numeric values are represented as strings that include a dollar sign, such as “$348.45”. The BigDecimal constructor accepts only valid numeric strings, so we need to remove the currency symbol or use a parsing utility before conversion.
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 ...
🌐
SSOJet
ssojet.com › dev guides › binary-to-text encodings › decimal in kotlin
Decimal in Kotlin | Developer Guides
December 25, 2025 - Displaying BigDecimal values for users requires careful formatting to ensure readability and accuracy. You can achieve this using DecimalFormat or String.format(), which allow precise control over decimal places, currency symbols, and thousands separators.
🌐
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`.
🌐
GitHub
github.com › detekt › detekt › issues › 5977
New Rule proposal: Use `String.toBigDecimalOrNull` instead of `BigDecimal(String)` constructor. · Issue #5977 · detekt/detekt · GitHub
April 7, 2023 - BigDecimal(String) constructor throws a NumberFormatException which is bad for performance and doesn't get caught by the type system, so might only be caught at runtime. String.toBigDecimalOrNull checks the value with a regex and avoids ...
Author: detekt
🌐
Java2Blog
java2blog.com › java-string-to-bigdecimal
Java String to BigDecimal – Java2Blog
You can simply use BigDecimal ‘s String based constructor to do it.
🌐
Baeldung
baeldung.com › home › kotlin › kotlin numbers › dividing two int objects and getting a bigdecimal in kotlin
Dividing Two Int Objects and Getting a BigDecimal in Kotlin | Baeldung on Kotlin
September 7, 2023 - Therefore, we recommend using the toBigDecimal() function from both readability and performance points of view. In this article, we’ve explored two approaches of dividing two integers and obtaining a BigDecimal with the decimal portion as ...
🌐
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.