형식화된 출력
Coddy Rust 여정의 Fundamentals 섹션에 포함된 레슨 — 75개 중 36번째.
챌린지
초급출력이 항상 소수점 둘째 자리까지 부동 소수점 값을 출력하도록 수정하세요. 이를 위해 {:.2} 기호를 사용하세요:
let num = 1.5576734;
println!("This is rounded: {:.2}", num);
// 출력: This is rounded: 1.56직접 해보기
use std::io;
fn main() {
println!("Calculator App");
let mut input_num1 = String::new();
let mut input_num2 = String::new();
io::stdin().read_line(&mut input_num1).unwrap();
io::stdin().read_line(&mut input_num2).unwrap();
let num1: f64 = input_num1.trim().parse().unwrap();
let num2: f64 = input_num2.trim().parse().unwrap();
let sum = num1 + num2;
let difference = num1 - num2;
let product = num1 * num2;
let quotient = num1 / num2;
println!("Sum: {}", sum);
println!("Difference: {}", difference);
println!("Product: {}", product);
println!("Quotient: {}", quotient);
}