简体   繁体   English

如何在 Rust 中打印 1 dec 和固定宽度的 F32

[英]How to print F32 with 1 dec place and a fixed width in rust

Trying to replicate the following C printf invocation尝试复制以下 C printf 调用

printf("%6.1f %6.1f %6.1f\n", x, y, z);

in rust and I can't find it in the docs.在 rust 中,我在文档中找不到它。 I need 6 positions wide with 1 decimal place.我需要 6 个位置宽 1 个小数位。

First time I've been stumped finding what I need there.我第一次在那里很难找到我需要的东西。

Formatting strings are documented in the documentation for std::fmt .格式化字符串记录在std::fmt的文档中。

The equivalent of %6.1f would be {:6.1} : %6.1f的等价物是{:6.1}

println!("{:6.1} {:6.1} {:6.1}", x, y, z);

Playground 操场

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM