typestar

Strings three ways in F#

printfn formats, sprintf returns, $-interpolation splices.

// Three ways to build strings: printfn formats, sprintf returns,
// and $-interpolation splices inline.
let hive = "Bramble"
let weightKg = 32.6

printfn "%s weighs %.1f kg" hive weightKg

let label = sprintf "%s-%d" hive 2026
printfn "Label: %s" label

let report = $"{hive} is at {weightKg} kg before the flow"
printfn $"Report: {report}"
printfn $"Rounded up: {ceil weightKg}"

How it works

  1. %.1f fixes decimals in the printf family.
  2. sprintf builds the string instead of printing it.
  3. $"{hive} is at {weightKg} kg" interpolates inline.

Keywords and builtins used here

The run, in numbers

Lines
13
Characters to type
380
Tokens
51
Three-star pace
70 tpm

At the three-star pace of 70 tokens a minute, this run takes about 44 seconds.

Type this snippet

Step 3 of 3 in Values, step 3 of 27 in Language basics.

← Previous Next →