3

In zig it is possible to print float values in decimal notation by using "{d}". This will automatically print the value at full precision. Is there way to specify the number of digits? Either for each value, or as some kind of global setting?

B_old
  • 1,141
  • 3
  • 12
  • 26

1 Answers1

10

This will limit the number of digits after the decimal point, with rounding and zero-padding:

format(w, "{d:.1}", .{0.05}) == "0.1"
format(w, "{d:.3}", .{0.05}) == "0.050"

More info

Dull Bananas
  • 892
  • 7
  • 29