Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zig print float precision

Tags:

zig

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?

like image 627
B_old Avatar asked May 14 '26 12:05

B_old


1 Answers

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

like image 136
Dull Bananas Avatar answered May 16 '26 17:05

Dull Bananas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!