I am trying to work a dividing problem and then give the user the correct answer in the event they entered it incorrectly. However, the two random numbers I generated are i32 and I'm going to need to round the answer to 3 decimal places. I came up with the following code but it gives an answer of zero everytime.
let correctans = f64::from( ( secondnum / firstnum ) * 1000 ).round() / 1000.0;
I have to use the f64 in order to call round and this was all I could find to typecast an int to a float although I would think diving two ints would make a float. This runs fine but it gives a zero answer every time.
What is the proper method to use to deal with this situation in rust?
Thanks,
Glenn