Skip to content

Commit

Permalink
test(samples): add new samples
Browse files Browse the repository at this point in the history
  • Loading branch information
kotlin-samples-pusher-bot authored and AlexanderPrendota committed Feb 29, 2024
1 parent fb824d7 commit fa7bec4
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
fun main() {
//sampleStart
// Formats to add zeroes and make a length of seven
// Formats an integer, adding leading zeroes to reach a length of seven characters
val integerNumber = String.format("%07d", 31416)
println(integerNumber)
// 0031416

// Formats with four decimals and sign
// Formats a floating-point number to display with a + sign and four decimal places
val floatNumber = String.format("%+.4f", 3.141592)
println(floatNumber)
// +3.1416

// Formats with uppercase for two placeholders
// Formats two strings to uppercase, each taking one placeholder
val helloString = String.format("%S %S", "hello", "world")
println(helloString)
// HELLO WORLD

// Formats a negative number to be enclosed in parentheses, then repeats the same number in a different format (without parentheses) using `argument_index$`.
val negativeNumberInParentheses = String.format("%(d means %1\$d", -31416)
println(negativeNumberInParentheses)
//(31416) means -31416
//sampleEnd
}

0 comments on commit fa7bec4

Please sign in to comment.