Unfortunately, there's no built-in support for formatting in string templates yet, as a workaround, you can use something like:

"pi = ${pi.format(2)}"

the .format(n) function you'd need to define yourself as

fun Double.format(digits: Int) = "%.${digits}f".format(this)

This will work only in Kotlin/JVM.

There's clearly a piece of functionality here that is missing from Kotlin at the moment, we'll fix it.

Answer from Andrey Breslav on Stack Overflow
๐ŸŒ
Kotlin
kotlinlang.org โ€บ docs โ€บ strings.html
Strings | Kotlin Documentation
February 4, 2026 - The String.format() function accepts a format string and one or more arguments. The format string contains one placeholder (indicated by %) for a given argument, followed by format specifiers.
People also ask

How to convert string to UTF-8 in Kotlin?
To convert a string to UTF-8 in Kotlin, you use the `toByteArray()` method with `Charsets.UTF\_8` as a parameter. This converts the `string` into a byte array encoded in UTF-8 format, suitable for transmission or storage where UTF-8 encoding is required.
๐ŸŒ
dhiwise.com
dhiwise.com โ€บ post โ€บ mastering-kotlin-string-formatting-what-you-need-to-know
Mastering Kotlin String Formatting: A Beginner's Guide
What is %s in Kotlin?
`%s` is a `format specifier` in Kotlin used with the `String.format()` method. It represents a string placeholder where the `string value` provided as an argument is inserted. `%s` helps in dynamically inserting `string values` into formatted output.
๐ŸŒ
dhiwise.com
dhiwise.com โ€บ post โ€บ mastering-kotlin-string-formatting-what-you-need-to-know
Mastering Kotlin String Formatting: A Beginner's Guide
๐ŸŒ
Kotlin
kotlinlang.org โ€บ api โ€บ core โ€บ kotlin-stdlib โ€บ kotlin.text โ€บ format.html
format | Core API โ€“ Kotlin Programming Language
See java.util.Formatter class documentation for the syntax of format specifiers for the format string. 1.0 ยท import kotlin.test.* import java.util.* import java.util.regex.* fun main() { //sampleStart // format negative number in parentheses val negativeNumberInParentheses = String.format("%(d means %1\$d", -31416) println(negativeNumberInParentheses) // (31416) means -31416 //sampleEnd } inline fun String.format(locale: Locale?, vararg args: Any?): String(source) Uses this string as a format string and returns a string obtained by substituting format specifiers in the format string with the provided arguments, using the specified locale.
๐ŸŒ
DhiWise
dhiwise.com โ€บ post โ€บ mastering-kotlin-string-formatting-what-you-need-to-know
Mastering Kotlin String Formatting: A Beginner's Guide
September 27, 2024 - Kotlin, being one of the modern programming languages, provides a flexible and powerful approach to string formatting through string templates, the String.format() method, and other utilities available in the String class.
๐ŸŒ
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
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ kotlin โ€บ kotlin strings โ€บ how does string interpolation work in kotlin?
How Does String Interpolation Work in Kotlin? | Baeldung on Kotlin
March 19, 2024 - String interpolation in Kotlin allows us to easily concatenate constant strings and variables to build another string elegantly.
Find elsewhere
๐ŸŒ
Kotlinlang
slack-chats.kotlinlang.org โ€บ t โ€บ 529771 โ€บ will-string-format-be-available-in-native
Will `String format` be available in native kotlinlang #kotlin-native
July 14, 2018 - Haven't tried it, but, this may work: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/format.html ... platform.posix.snprintf, but it's not exactly the same - outputs utf-8 string to preallocated C buffer.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ kotlin โ€บ kotlin strings โ€บ kotlin string templates
Kotlin String Templates | Baeldung on Kotlin
March 19, 2024 - Kotlin has enriched the Java String class with additional functionality. For example, the method padEnd() allows us to format a String, so that the expression:
๐ŸŒ
Regex101
regex101.com
regex101: build, test, and debug regex
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.
๐ŸŒ
Kotlin Discussions
discuss.kotlinlang.org โ€บ t โ€บ java-string-format-alternative-in-kotlin โ€บ 703
Java String.format alternative in kotlin? - Kotlin Discussions
November 18, 2013 - Hi, Iโ€™m using java String.format in my codes which i want to port to kotlin. For example String log = String.format(โ€œ%d, %s, o : ?โ€, value1, value2, value3, value4) How to convert above java code to kotlin? Thanโ€ฆ
๐ŸŒ
Supabase
supabase.com โ€บ docs โ€บ guides โ€บ database โ€บ tables
Tables and Data | Supabase Docs
13 hours ago - When inserting large data sets it's best to use Postgres's COPY command. This loads data directly from a file into a table. There are several file formats available for copying data: text, CSV, binary, JSON, etc.
๐ŸŒ
GitHub
github.com โ€บ skylot โ€บ jadx
GitHub - skylot/jadx: Dex to Java decompiler ยท GitHub
February 18, 2026 - jadx[-gui] [command] [options] ... for Kotlin lambdas --no-finally - don't extract finally block --no-restore-switch-over-string - don't restore switch over string --no-replace-consts - don't replace constant value with matching constant field --escape-unicode - escape non latin characters in strings (with \u) --respect-bytecode-access-modifiers - don't change original access modifiers --mappings-path - deobfuscation mappings file or directory. Allowed formats: Tiny and ...
Starred by 48.2K users
Forked by 5.5K users
Languages ย  Java 92.1% | Smali 6.5% | Kotlin 1.1%
๐ŸŒ
Kotlin Discussions
discuss.kotlinlang.org โ€บ t โ€บ how-to-apply-template-to-a-string-returned-from-a-function โ€บ 942
How to apply template to a string returned from a function - Kotlin Discussions
January 17, 2013 - In Android text can be put on a resource file like <string name="download_all">Download all $name</string> and it can be retrieved by a call such as getString(download_all) The problem is the template expression doeโ€ฆ
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ kotlin โ€บ strings
Kotlin | Strings | Codecademy
October 24, 2023 - In Kotlin, string values are always defined as instances of the String class.
๐ŸŒ
Stonesoupprogramming
stonesoupprogramming.com โ€บ 2017 โ€บ 11 โ€บ 17 โ€บ kotlin-string-formatting
Kotlin String Formatting โ€“ Stone Soup Programming
November 6, 2017 - Using Kotlin String templates Bob is a good chef Bob is a great chef %[flags][width][.precision]type Formatting Symbols %b Boolean %c Character %d Signed Integer %e Float in scientific format %f Float in decimal format %g Float in either decimal or scientific notation based on value %h Hashcode of argument %n Line separator %o Octal Integer %s String %t Date or Time %x Hexadecimal Integer
๐ŸŒ
JetBrains
plugins.jetbrains.com โ€บ plugin โ€บ 18563-replace-string-format-with-kotlin-string-template
Replace String.format with Kotlin String Template - IntelliJ IDEs Plugin | Marketplace
Quickly add named parameters to all callers of a Kotlin class, method or file. Using it is easy: Place your cursor in a String.format call in a Kotlin fileSearch for...
๐ŸŒ
Medium
hanru-yeh.medium.com โ€บ quick-note-string-construction-in-kotlin-string-templates-vs-stringbuilder-and-buildstring-88d75c79dfdd
String Construction in Kotlin - String Templates vs. StringBuilder and buildString | by Bram Yeh | Medium
December 19, 2023 - In general, Kotlin programmers favor string templates over string concatenation or String.format(). String templates offer a concise and readable syntax for embedding expressions directly into strings.
๐ŸŒ
Model Context Protocol
modelcontextprotocol.io โ€บ docs โ€บ develop โ€บ build-client
Build an MCP client - Model Context Protocol
This helper converts a kotlinx.serialization JsonObject to an Anthropic SDK JsonValue using Jackson: private fun JsonObject.toJsonValue(): JsonValue { val mapper = ObjectMapper() val node = mapper.readTree(this.toString()) return JsonValue.fromJsonNode(node) } Now letโ€™s add the core functionality for processing queries and handling tool calls: suspend fun processQuery(query: String): String { val messages = mutableListOf( MessageParam.builder() .role(MessageParam.Role.USER) .content(query) .build(), ) val response = anthropic.messages().create( MessageCreateParams.builder() .model("claude-so
๐ŸŒ
Google
developers.google.com โ€บ admob โ€บ mobile ads sdk (android) โ€บ enable test ads
Enable test ads | Android | Google for Developers
List<String> testDeviceIds = Arrays.asList("TEST_DEVICE_ID"); RequestConfiguration configuration = new RequestConfiguration.Builder().setTestDeviceIds(testDeviceIds).build(); MobileAds.setRequestConfiguration(configuration);
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_strings.php
C Strings
To output the string, you can use the printf() function together with the format specifier %s to tell C that we are now working with strings: