From 383ece674bd92a76987083a9607d6a57920fd828 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 28 Jan 2022 09:57:21 +0800 Subject: [PATCH] fix wrong indents and float number formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 控制小数位为 2 位应该是 `{:.2}` 。 `{:02}` 是对整体宽度不足 2 位的数字补前导 0 。 --- book/contents/basic/base-type/numbers.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/contents/basic/base-type/numbers.md b/book/contents/basic/base-type/numbers.md index f2877da9..07559796 100644 --- a/book/contents/basic/base-type/numbers.md +++ b/book/contents/basic/base-type/numbers.md @@ -126,8 +126,8 @@ fn main() { 42.0_f32, ]; -// 打印数组中第一个值,其中控制小数位为2位 -println!("{:02}", forty_twos[0]); + // 打印数组中第一个值,并控制小数位为2位 + println!("{:.2}", forty_twos[0]); } ```