Printing floats with runtime known precision

In a more similar fashion to the C examples you provided, you can use a runtime value in the args tuple or struct to fill in parts of the format specifier. You put the index or field name in square brackets []. In this example, I use the second arg of the tuple (index 1) as the precision:

std.debug.print("{d:.[1]}\n", .{ 3.1415, 2 });
12 Likes