Float Primitives
f32 และ f64 types
Basic Usage
Section titled “Basic Usage”fn main() { // Default is f64 let x = 3.14; // f64 let y: f32 = 2.71; // f32
println!("f64: {}", x); println!("f32: {}", y);
// With suffix let a = 1.0f32; let b = 1.0f64;
// Scientific notation let big = 1.5e10; let small = 1.5e-10; println!("Big: {}, Small: {}", big, small);
// Size println!("\n=== Size ==="); println!("f32: {} bytes", std::mem::size_of::<f32>()); println!("f64: {} bytes", std::mem::size_of::<f64>());
// Precision println!("\n=== Precision ==="); let pi_32: f32 = 3.14159265358979323846; let pi_64: f64 = 3.14159265358979323846; println!("f32 pi: {:.20}", pi_32); println!("f64 pi: {:.20}", pi_64);}เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google