I'm trying to do something for an assignment and we have to use a float variable. I was getting really messed up results and I couldn't figure out why so I wrote this program just to test some stuff and the results I don't understand.
If I enter in a small number say 45 the output is 45.00 which is correct. Same as something like 999.99 it prints 999.99Code:#include <stdio.h> int main() { float f; scanf("%f", &f); printf("%.2f\n", f); return 0; }
If I enter larger numbers (well within the float value range), say 123456789 it prints 123456792.00 (92 at the end huh?) Or something like 12345678901234567890 it prints 12345679395506094080.00 which is totally off. I'm just using ANSI C any ideas what is going on ?
According to MSDN Float in C should be able to go from 1.175494351 E – 38 to 3.402823466 E + 38 so my numbers easily within those values.