/*
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
*/
object FixedWidthFields {
/**
* Formats a record using fixed-width fields.
*
* %-15s = left-aligned string, width 15
* %10d = right-aligned integer, width 10
* %12.2f = right-aligned decimal number, width 12,
* with 2 digits after the decimal point
*/
def formatRecord(name: String, age: Int, salary: Double): String = {
f"$name%-15s$age%10d$salary%12.2f"
}
def main(args: Array[String]): Unit = {
// Store the formatted string in a variable
val result = formatRecord("Alice", 26, 125000.0)
println(result)
}
}
/*
run:
Alice 26 125000.00
*/