If it is an integer, even the preceding chapter has calculated the integer and the real number by the real number.

The mixture calculation had not been done by the integer and 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

Moreover, when having displayed it by way of experiment as an integer by %d finger fixed child, it became the following.

Obviously, it is understood that it is a strange value.

-10486

Because a display here changes depending on the compiler, it doesn't thoroughly become it.

..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,

1.05 is converted into the integer, and it is treated as one.

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

If parentheses are not applied, 1.05 is previously converted It is because of becoming one, and becoming meaningless.

The calculation order is important to decrease a peculiar error margin to the computer in this manner.

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.

< - It is advanced -> | in | head that returns to returning next |.