If it is an integer, even the preceding chapter has calculated the integer and the real number by the real number.
It is a calculation like For instance, the mixture calculation of the integer and the real number is 1.03×9.
In this calculation, real number × integer is calculated.
How does the answer become it in such a case?
In this case, the result becomes a real number if it says from the conclusion.
In C language, the result when calculating by the integer and the real number is converted into the real number.
This is because the real number part is lost when the result is made an integer.
The following program actually : It is an example of calculating 1.03×9.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { printf("%f\n",1.03 * 9); return 0; }
Certainly, I think that it is understood that the answer has been converted into the real number.
9.270000
Obviously, it is understood that it is a strange value.
-10486
..answer.. I see in the calculation of the integer and the real number ..becoming the real number...
However, when the answer of the integer is more convenient, it is thought according to circumstances.
For instance, though it is an expression of calculation of the consumption tax 1.05 amount of money × and (as of 2004/09/14)
If this calculation is usually done, the answer becomes a real number.
It is unnatural that the decimal is included in the amount of money.
This problem solves the real number if there is a method of conversion into the integer.
In C language, there is a casting conversion as a function to convert the type compulsorily.
The usage of the casting conversion becomes as follows.
[ Casting conversion ]
Function to convert type compulsorily
(converted type name) Numerical value and variable identifierFor instance, it is a real number value When you want to convert 1.05 into the integer In assumption as (int)1.05,
If this method is used, the calculation of the consumption tax becomes possible, too.
The following program is an example of requesting the consumption tax of the commodity of 360 yen.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { printf("%d\n",(int)(1.05 * 360)); return 0; }
In this program, to 1.05×360 Calculating applying () :.
378
The numerical result of the real number and the value in which it is converted into the integer : according to the kind of the compiler and the computer.
Because it is likely to differ somewhat, it is likely not to become fit 378.
It is possible to use the casting conversion for the variable naturally, and the usage is the same.