※スタイルシート未対応ブラウザではレイアウトを正確に再現できません。
> | advanced by | contents  | that returns in <
< [modosusu] > Color magazine monochrome light and shade   font predetermined, Gothic Ming-style type longhand   size Konaka large   standard

Digit arrangement of numerical value

1. ..clause 1..: Digit arrangement of integer
2. ..clause 2..: Computational display
3. ..clause 3..: Digit arrangement of real number

[1] Digit arrangement of integer

The function not to have explained yet is provided though it is printf function that has been frequently used up to now.
The printf function can specify the digit number for displayed character and numerical value.

The digit number leaves printf to the following program up to now.

```
#include <stdio.h>

int main(void)
{
int a = 10000,b = 500,c = 3;

Printf ("A is %d.  \n" a);
Printf ("B is %d.  \n" b);
Printf ("C is %d.  \n" c);

return 0;
}
```
The execution result of this program becomes as follows.

A 100.
B 50.
C 3. [Desu].
The figure is displayed as it is as understood even if the result is seen.
The position with other figures shifts.
When many figures with more digit numbers are displayed, it becomes difficult to read very much.

Do as follows to arrange the digit number by the printf function.

Number d of % digits
Put and display the blank to become the digit number if the figure is put between output conversion finger fixed children.
The following program is an example of the legible doing specifying the digit number for five digits.
```
#include <stdio.h>

int main(void)
{
int a = 10000,b = 500,c = 3;

Printf ("A is %5d.  \n" a);
Printf ("B is %5d.  \n" b);
Printf ("C is %5d.  \n" c);

return 0;
}
```
The execution result of this program becomes as follows.

A 100.
B   50.
C     3. [Desu].
It is put the blank according to the digit number and is legible though understands when the result is seen.
Match it to the digit number for the numerical value when the digit number for the numerical value is larger than the specified digit number.

Therefore, whenever the expected maximum digit number is specified, the digit is arranged and displayed.
..-.. because the sign is handled as one digit when you display a minus value moreover
It specifies it one digit more greatly when there is a possibility of displaying the value of the minus.

It returns to contents.

[2] Computational display

In the printf function, the display that uses 0 often seen with the computer is possible.
Come to display to put 0 ahead of the digit number putting 0 instead of the blank.
The following program is an example of the change to put 0 on the head.

```
#include <stdio.h>

int main(void)
{
int a = 10000,b = 500,c = 3;

Printf ("A is %05d.  \n" a);
Printf ("B is %05d.  \n" b);
Printf ("C is %05d.  \n" c);

return 0;
}
```
The execution result of this program becomes as follows.

A 100.
B 005.
C 000.
I must think that it is a display like the computer somehow.

It returns to contents.

[3] Digit arrangement of real number

In the display of the real number value, the number of decimals can be specified with the entire digit number.
Number of the entire % digits. Number f of decimal digits
The number of whole digits is that what should be noted here contains the digit number and the decimal point of the decimal.
For instance, the integer part is treble, and it is interpreted in %6.2f as six digits whose the decimal point is one digit, and fractional portions are two digits.

The following program is an example of displaying the real number value by the digit specification.

```
#include <stdio.h>

int main(void)
{
double pi = 3.14159;
printf("%6.2f\n",pi);
printf("123456\n");
return 0;
}
```
The execution result of this program becomes as follows.

3.14
123456
The line below is the one having put it to make the digit number easy to see.
It is understood six digits the whole, one digit the decimal point, two digits the fractional portion, and to be displayed.
If the number of decimals is adjusted to 0, the decimal point is not displayed.

Other various specification can be done.
Refer to an output conversion finger fixed child of the word and the sign for details.

It returns to contents.

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