Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Xiaobai has solved the problem of division output after the conversion of C language type from int to double, and there is no addition, subtraction, multiplication and division.
Xiaobai has solved the problem of division output after the conversion of C language type from int to double, and there is no addition, subtraction, multiplication and division.
There is something wrong with the last printf statement, (double)(a/b). Before the conversion, a/b operation has been carried out, because both A and B are of int type, so the result of division is also of int type (rounding). When they are converted into double type, the decimal part has become 0, and (double)a/b is to convert A into double type and then divide by B.

For example: (double)( 1/2), the result of 1/2 is 0, and (double)( 1/2) is 0.000000.

(double) 1/2 is actually 1.000000/2, and the result is 0.500000.