/*
Common width 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 // Float, width 12, precision 2
*/
package main
import (
"fmt"
)
// formatRecord formats data into fixed-width columns.
//
// %-15s : left-aligned string, width 15
// %10d : right-aligned integer, width 10
// %12.2f: right-aligned float, width 12,
// with 2 digits after the decimal point
func formatRecord(name string, age int, salary float64) string {
return fmt.Sprintf(
"%-15s%10d%12.2f",
name,
age,
salary,
)
}
func main() {
// Store the formatted result in a variable
result := formatRecord("Abby", 32, 98000.0)
fmt.Println(result)
}
/*
run:
Abby 32 98000.00
*/