How to declare a real variable with at least 20 digits in Rust

1 Answer

0 votes
fn main() {
    // Start with a string to preserve input precision
    let input = "3.141592653589793238462643";
    
    // Parse to f64 – keep in mind this loses precision beyond ~15 digits
    let x: f64 = input.parse().unwrap();

    println!("Approximate value: {:.21}", x);
}


/*
run:

3.141592653589793238462643

*/

 



answered Jun 26, 2025 by avibootz
...