Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 zig 中,可以使用“{d}”以十进制表示法打印浮点值。这将自动以全精度打印该值。有没有办法指定位数?对于每个值,还是作为某种全局设置?
这将限制小数点后的位数,四舍五入和零填充:
format(w, "{d:.1}", .{0.05}) == "0.1" format(w, "{d:.3}", .{0.05}) == "0.050"
更多信息