Osy#the first language built for agents
Agents firstAgentic appsWorkflowsDurable Execution — built inSecurityTestingThe editorThe UI modelOne program

Reference / Function

String interpolation & format specifiers

$"…{expr}…{expr:format}…"

Build a string from literal text and embedded expressions with $"…{expr}…". A hole may carry a .NET format specifier after a colon ({amount:F2}), applied via IFormattable in InvariantCulture — exactly C#.

stable1 example compiled by CIfunctionstringauthoring

Summary#

$"…{expr}…" builds a string from literal text and embedded expressions. A hole may carry a .NET format specifier after a colon — {amount:F2} — applied via IFormattable in InvariantCulture, exactly like C#'s string.Format.

Signature#

$"literal {expr} more {expr:format} text"

Description#

  • Each {expr} hole is converted to its string form and concatenated with the surrounding literal text.
  • A :format after the expression applies a .NET format string to a formattable value (numbers, dates): {total:F2} → two decimals, {n:N0} → thousands separators, {ratio:P1} → a percent, {when:yyyy-MM-dd} → a date. Formatting always uses InvariantCulture (deterministic across hosts).
  • A non-formattable value (a string) ignores the specifier and coerces as usual — matching C#'s string.Format.
  • The formatted conversion is also available directly as the 2-arg Convert.ToString(value, "F2").

Examples#

string Money(decimal amount) { return $"Total: {amount:F2}"; }   // "Total: 1234.50"
string Thousands(int n) { return $"{n:N0}"; }                    // "1,234,567"
string Percent(decimal ratio) { return $"{ratio:P1}"; }          // "12.3 %"
string Plain(int n) { return $"n = {n}"; }                       // "n = 5" (no specifier)
string Direct(decimal d) { return Convert.ToString(d, "F3"); }   // "3.142"

See also#

Related

Numeric types & literal suffixes

The platform numeric types are int, long, decimal, and double. Literals follow C# exactly, suffixes (L, m, d) included:…

Convert

Explicit conversion between types — number to text, text to number, a Guid to its text form. Osy# will not convert…