Files
pebble/examples/basic/23_format_spec.peb

33 lines
518 B
Plaintext

// Basic type
let a = 42
print(f"int: {a:d}; hex: {a:x}; HEX: {a:X}; oct: {a:o}; bin: {a:b}")
// Grouping
let b = 1234567890
print(f"{b:,}")
print(f"{b:_}")
let c = 1234.5678
print(f"{c:,._}")
print(f"{c:_.,}")
// Sign
let d1 = 14
let d2 = -26
print(f"{d1} {d2}")
print(f"{d1:+} {d2:+}")
print(f"{d1:-} {d2:-}")
print(f"{d1: } {d2: }")
// Percentage
let pts = 19
let total = 22
print(f"Correct answers: {pts/total:.2%}")
// Precision
print(f"{c:8}")
print(f"{c:8.2}")
print(f"{c:.2}")
print(f"{c:.8}")
// Complex