Been trying to get the outputs to give me the number without rounding, not sure what I'm missing
float NumberOfTrees1; for (NumberOfTrees1 = 1000.0; NumberOfTrees1 >= 50; NumberOfYears++) { NumberOfTrees1 = NumberOfTrees1 - (NumberOfTrees1 * 0.13); printf("Number of Remaining Trees: %0.1f\n",NumberOfTrees1); } My Output:
Number of Remaining Trees: 61.7 Number of Remaining Trees: 53.7 Number of Remaining Trees: 46.7 Required Output:
Number of Remaining Trees: 61 Number of Remaining Trees: 53 Number of Remaining Trees: 46 I understand that the %0.1f is what gives me the .7 but when I use %0.0f it rounds up my numbers which I don't want. Been switching things around from using int, double, long float etc to no avail.
Any help would be great and thank you in advance!!!
floor()function.double(andfloat) itself is rounded naturally (0.1 + 0.2results in a rounded0.3)... but just use"%a"to print all the bits (in hexadecimal):printf("0.3 rounded is %a\n", 0.1 + 0.2);