Reputation: 1291
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?
Upvotes: 9
Views: 4846
Reputation: 1052
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"
Upvotes: 16