/*
Common format specifiers
-----------------------------------
%-10s // Left-aligned string, width 10
%10s // Right-aligned string, width 10
%5d // Integer, width 5
%08d // Integer, width 8, padded with zeros
%12.2f // Floating-point, width 12, 2 decimal places
*/
/**
* Formats a record using fixed-width fields.
*
* %-15s = left-aligned string, width 15
* %10d = right-aligned integer, width 10
* %12.2f = right-aligned floating-point number,
* width 12, 2 decimal places
*/
fun formatRecord(name: String, age: Int, salary: Double): String {
return String.format(
"%-15s%10d%12.2f",
name,
age,
salary
)
}
fun main() {
// Store the formatted string in a variable
val result = formatRecord("Silvia", 23, 169000.0)
println(result)
}
/*
run:
Silvia 23 169000.00
*/