How to convert float to string in let if block?

Block_2 does not work.
How to start block_2 instead of block_1?
play

fn main() {

    let n2: f64 = 0.1;
    
    let n2: String = if n2 == 0.0 {
        "".to_string() 
    } else {
        // block 1.
        "text: ".to_string() + &n2.to_string()
        
        // block 2.
        /*
        if n2 > 0.0 {
           "text_1: ".to_string() + &n2.to_string()
        }
        if n2 < 0.0 {
           "text_2: ".to_string() + &n2.to_string()
        }
        */ 
    };
 
println!("{}", &n2);   
}

You need to insert else before the if n2 < 0.0 and add a final else for the cases where n2 is neither less than nor greater than 0.0.

Playground

1 Like

it is clear, else is mandatory
thanks