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
Discussions

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
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
Format a double to fixed decimal length - Support - Kotlin Discussions
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? More on discuss.kotlinlang.org
🌐 discuss.kotlinlang.org
1
November 28, 2020
🌐
Android Developers
developer.android.com › api reference › numberformat
NumberFormat | 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 · 中文 – 简体
🌐
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

🌐
Kotlin
kotlinlang.org › api › latest › jvm › stdlib › kotlin.text › format.html
format - Kotlin Programming Language
August 9, 2023 - import java.util.Locale import kotlin.test.* fun main(args: Array<String>) { //sampleStart // format with German conventions val withGermanThousandsSeparator = "%,d".format(Locale.GERMANY, 12345) println(withGermanThousandsSeparator) // 12.345 // 12.345 // format with US conventions val withUSThousandsSeparator = "%,d".format(Locale.US, 12345) println(withUSThousandsSeparator) // 12,345 //sampleEnd }
🌐
Lets-plot
lets-plot.org › kotlin › formats.html
Formatting | Lets-Plot for Kotlin
March 20, 2026 - Formatting provides the ability to do complex variable substitutions and value formatting · The numeric format strings are used to format common numeric types. The general form of a format specifier is:
🌐
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin.text › format.html
format | Core API – Kotlin Programming Language
import kotlin.test.* import java.util.* import java.util.regex.* fun main() { //sampleStart // format with German conventions val withGermanThousandsSeparator = String.format(Locale.GERMANY, "%,d", 12345) println(withGermanThousandsSeparator) // 12.345 // format with US conventions val withUSThousandsSeparator = String.format(Locale.US, "%,d", 12345) println(withUSThousandsSeparator) // 12,345 //sampleEnd }
🌐
GitHub
github.com › valiktor › valiktor › blob › master › valiktor-core › src › main › kotlin › org › valiktor › i18n › formatters › NumberFormatter.kt
valiktor/valiktor-core/src/main/kotlin/org/valiktor/i18n/formatters/NumberFormatter.kt at master · valiktor/valiktor
import java.text.NumberFormat · · /** * Represents the formatter for [Number] values · * * @author Rodolpho S. Couto · * @since 0.1.0 · */ object NumberFormatter : Formatter<Number> { · override fun format(value: Number, messageBundle: MessageBundle): String { val bigNum = value as?
Author   valiktor
Find elsewhere
🌐
JetBrains
youtrack.jetbrains.com › issue › KT-21644 › Add-utility-function-for-formatting-of-decimal-numbers-to-Kotlin-common-library
Add utility function for formatting of decimal numbers to ...
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
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?

🌐
Kotlinlang
slack-chats.kotlinlang.org › t › 27112018 › is-there-a-decimalformat-or-numberformat-equivalent-library-
Is there a DecimalFormat or NumberFormat equivalent library kotlinlang #multiplatform
iosMain import platform.Foundation.NSLocale import platform.Foundation.NSNumber import platform.Foundation.NSNumberFormatter import platform.Foundation.NSNumberFormatterCurrencyStyle private val formatter = NSNumberFormatter().apply { locale = NSLocale(localeIdentifier = "DE") currencyCode = "eur" numberStyle = NSNumberFormatterCurrencyStyle } actual fun parseFormattedStringToCents(formattedAmount: String): BigInteger { return BigInteger(formatter.numberFromString(formattedAmount)?.longValue ?: 0L) } actual fun formatMoney(amount: Double): String { val number = NSNumber(amount) return formatte
🌐
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.
🌐
JetBrains
youtrack.jetbrains.com › issue › KT-21644
Add utility function for formatting of decimal numbers to Kotlin ...
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
Sling Academy
slingacademy.com › article › formatting-numbers-for-display-in-kotlin-currency-percentages
Formatting Numbers for Display in Kotlin (Currency, Percentages) - Sling Academy
To format numbers into currency, Kotlin can leverage the DecimalFormat class from Java, which allows custom formatting options. import java.text.DecimalFormat fun main() { val format = DecimalFormat("#,##0.00") val price = 1234.50 println("Formatted price in default locale: $" + format.for...
🌐
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?
🌐
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?
🌐
Spark By {Examples}
sparkbyexamples.com › home › kotlin › format string in kotlin with examples
Format String in Kotlin With Examples - Spark By {Examples}
May 9, 2024 - How to format a string in Kothin? Formatting string is a standard operation in most programming languages, including Kotlin. In Kotlin, you can use the