This is the format you need:

val dec = DecimalFormat("#,###.##")

will print:

5.384,45

if you need always exactly 2 digits after the decimal point:

val dec = DecimalFormat("#,###.00") 
Answer from forpas on Stack Overflow
🌐
Baeldung
baeldung.com › home › kotlin › kotlin numbers › number formatting in kotlin
Number Formatting in Kotlin | Baeldung on Kotlin
March 26, 2025 - Now, we’ve already mentioned Kotlin’s extension functions. Another solution to this problem is to create an extension function to do the formatting on the input data class. For example, since our example input is a Double number, we can create an extension function on the Double class:
Discussions

Decimal format in a multi-platform build - Libraries - Kotlin Discussions
I am trying to converting one of my JavaFX projects to a multi-platform one. Since I do not have any experience with javascript ecosystem it is moving very slow. One specific problem I encountered, that there seems to be no way to define a format for numbers in common library. More on discuss.kotlinlang.org
🌐 discuss.kotlinlang.org
0
December 6, 2017
java - Kotlin. How to format decimal number with zero at the end? - Stack Overflow
I need to format the number. ... I need to add zero at the end if there is one digit after the decimal point. ... Have a look at my answer. I get the results you want, using some IF logic and String manipulation. ... Hint: DecimalFormat is a java class. This is nothing to do with kotlin. More on stackoverflow.com
🌐 stackoverflow.com
DecimalFormat and NumberFormat libs for Kotlin Multiplatform ?
If you really want to go down this route it's likely you'll have to roll your own https://youtrack.jetbrains.com/issue/KT-21644/Add-utility-function-for-formatting-of-decimal-numbers-to-Kotlin-common-library Seems like a good opportunity for an open source project! :) However, Imo best practice would be to keep this type of device specific display formatting out of shared business logic and implement it in the platform specific code where you have access to things like Locale to inform how you format the numbers. More on reddit.com
🌐 r/Kotlin
1
12
April 14, 2023
DecimalFormat for Kotlin Multiplatform
I just used the expect/actual modifiers to create a formatting interface in the Multiplatform library, and then implemented it on Android using DecimalFormat and on iOS with NSNumberFormatter. It's a little extra work, but not too bad. More on reddit.com
🌐 r/Kotlin
4
2
September 21, 2020
🌐
Kotlin Discussions
discuss.kotlinlang.org › support
Format a double to fixed decimal length - Support - Kotlin Discussions
November 28, 2020 - Hi I want to round a Double (12345.12345) to a String with a fixed length after the ‘.’ Example: 12345.123 And: if it is 12345.1 It still should give me 12345.100 How can I do this in kotlin?
🌐
Programiz
programiz.com › kotlin-programming › examples › round-number-decimal
Kotlin Program to Round a Number to n Decimal Places
import java.math.RoundingMode import java.text.DecimalFormat fun main(args: Array<String>) { val num = 1.34567 val df = DecimalFormat("#.###") df.roundingMode = RoundingMode.CEILING println(df.format(num)) }
🌐
Android Developers
developer.android.com › api reference › decimalformat
DecimalFormat | 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 Discussions
discuss.kotlinlang.org › libraries
Decimal format in a multi-platform build - Libraries - Kotlin Discussions
December 6, 2017 - I am trying to converting one of my JavaFX projects to a multi-platform one. Since I do not have any experience with javascript ecosystem it is moving very slow. One specific problem I encountered, that there seems to be no way to define a format for numbers in common library.
🌐
Lets-plot
lets-plot.org › kotlin › formats.html
Formatting | Lets-Plot for Kotlin
1 month ago - %M - minute as a zero-padded decimal number (00, 01, …, 59); %p - "AM" or "PM" according to the given time value; ... If no timezone information is present (naive datetime), Lets-Plot assumes UTC timezone.
Find elsewhere
🌐
Reddit
reddit.com › r/kotlin › decimalformat and numberformat libs for kotlin multiplatform ?
r/Kotlin on Reddit: DecimalFormat and NumberFormat libs for Kotlin Multiplatform ?
April 14, 2023 -

I'm working on a multiplatform library with Kotlin

We need to display numbers with either "comma decimal " and "dot decimal" formats based on the locale

For example

  1. 1,00,000.50 for India , 1.00.00,50 for Europe

For this purpose I used Java's number format and Decimal format classes

DecimalFormat decim = new DecimalFormat("#,###.##"); tv.setText(decim.format(someFloat));

OR

NumberFormat.getInstance().format(my number) 

Both are good, but they are JAVA libraries won't work in KMM code

So, my question, is there any DecimalFormat and NumberFormat alternate libraires available for Kotlin Multiplatform ?

I don't like to use Expect / Actual implementation but a native ones

🌐
Reddit
reddit.com › r/kotlin › decimalformat for kotlin multiplatform
r/Kotlin on Reddit: DecimalFormat for Kotlin Multiplatform
September 21, 2020 -

Hello,

I'm trying to build a multiplatform library with Kotlin. The library I'm building deals with logic for formatting decimal. The only easy way I know for this would be to use Java DecimalFormat but since this is going to be multi-platform, using anything from Java is not possible. I noticed there is this open issue related to decimal formatting for Kotlin multiplatform: https://youtrack.jetbrains.com/issue/KT-21644?_ga=2.88225499.1133820560.1600725580-928101732.1566781632. So I guess currently there is no multiplatform library for decimal format? If you happened to run into this, what was your work around? Did you end up having to create your own library from scratch?

🌐
GitHub
gist.github.com › januprasad › 0f059f365f7c2aa95e60ae19db0ed6d4
DecimalFormat in kotlin · GitHub
DecimalFormat in kotlin · Raw · DecimalFormat.kt · This file contains hidden or 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.
🌐
Kotlin Discussions
discuss.kotlinlang.org › support
How do you round a number to N decimal places - Support - Kotlin Discussions
August 2, 2018 - So I saw this post about my problem(Print floats with certain amount of decimal numbers) And I was wondering I it possible to use a methood or something else rather “%.2f”.format(value) in order to achive the same thing …
🌐
GitHub
gist.github.com › nprk › 999faa0d324e54bd59bae7def933b495
Kotlin: compact decimal format (1200 -> 1.2k) · GitHub
Kotlin: compact decimal format (1200 -> 1.2k). GitHub Gist: instantly share code, notes, and snippets.
🌐
SSOJet
ssojet.com › binary-encoding-decoding › decimal-in-kotlin
Decimal in Kotlin | Binary to Text Encodings in Programming Languages
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.
🌐
TutorialsPoint
tutorialspoint.com › kotlin-program-to-round-a-number-to-n-decimal-places
Kotlin Program to Round a Number to n Decimal Places
fun main() { val myInput = 3.1415 println("The number is defined as $myInput") println("The result after rounding the number to 3 decimal places is: ") println("%.3f".format(myInput)) } The number is defined as 3.1415 The result after rounding the number to 3 decimal places is: 3.142 · In ...
Top answer
1 of 15
174

Finally I did what Andy Turner suggested, rounded to 3 decimals, then to 2 and then to 1:

Answer 1:

val number:Double = 0.0449999
val number3digits:Double = String.format("%.3f", number).toDouble()
val number2digits:Double = String.format("%.2f", number3digits).toDouble()
val solution:Double = String.format("%.1f", number2digits).toDouble()

Answer 2:

val number:Double = 0.0449999
val number3digits:Double = Math.round(number * 1000.0) / 1000.0
val number2digits:Double = Math.round(number3digits * 100.0) / 100.0
val solution:Double = Math.round(number2digits * 10.0) / 10.0

Result:

0.045 → 0.05 → 0.1

Note: I know it is not how it should work but sometimes you need to round up taking into account all decimals for some special cases so maybe someone finds this useful.

2 of 15
84

I know some of the above solutions work perfectly but I want to add another solution that uses ceil and floor concept, which I think is optimized for all the cases.

If you want the highest value of the 2 digits after decimal use below code.

import java.math.BigDecimal 
import java.math.RoundingMode
import java.text.DecimalFormat

here, 1.45678 = 1.46

fun roundOffDecimal(number: Double): Double? {
    val df = DecimalFormat("#.##")
    df.roundingMode = RoundingMode.CEILING
    return df.format(number).toDouble()
}

If you want the lowest value of the 2 digits after decimal use below code.

here, 1.45678 = 1.45

fun roundOffDecimal(number: Double): Double? {
    val df = DecimalFormat("#.##")
    df.roundingMode = RoundingMode.FLOOR
    return df.format(number).toDouble()
}

Here a list of all available flags: CEILING, DOWN, FLOOR, HALF_DOWN, HALF_EVEN, HALF_UP, UNNECESSARY, UP

The detailed information is given in docs

🌐
Kotlin Discussions
discuss.kotlinlang.org › support
Print floats with certain amount of decimal numbers - Support - Kotlin Discussions
June 20, 2016 - Hello, I am trying to print a float with two decimal symbols. How to do that?
🌐
Baeldung
baeldung.com › home › kotlin › kotlin numbers › rounding numbers in kotlin
Rounding Numbers in Kotlin | Baeldung on Kotlin
September 7, 2024 - We set the rounding mode to RoundingMode.DOWN. We also set the scale to 1. As expected, the number is rounded down towards zero to a single decimal place. There are a number of other rounding modes we can use. For example, RoundingMode.CEILING rounds to positive infinity:
🌐
CopyProgramming
copyprogramming.com › howto › decimal-format-in-kotlin
Kotlin Floats and Decimal Formatting: A Complete 2026 Guide - Kotlin do floats only have one decimal in kotlin
December 30, 2025 - It offers approximately 6-7 significant decimal digits of total precision, which means the number of decimal places you can accurately represent depends on how many digits appear before the decimal point. For example, a float value like 4294967.0 uses 24 bits of precision, leaving virtually ...