vault backup: 2024-09-11 12:16:34
This commit is contained in:
parent
2a86cc053b
commit
4519740ea7
@ -30,4 +30,13 @@ A variable must be declared before it is assigned.
|
||||
| Specifier | Function |
|
||||
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `%d` | Display an integer |
|
||||
| `%f` | Display a float. Specify the number of places to round to by adding a decimal and a number, eg `%.2f` would round to two decimal places. |
|
||||
| `%f` | Display a float. Specify the number of places to round to by adding a decimal and a number, eg `%.2f` would round to two decimal places. |
|
||||
For number formatting specifiers, the convention is as follows:
|
||||
`%-a.bX`
|
||||
`%`: Start of the formatting specifier
|
||||
`-`: (optional) If included, justify value left in space. Otherwise, justify right in space
|
||||
`a`: (optional) If included, the size of the field in characters.
|
||||
`.`: Separator between `a` and `b`. Optional if `b` is not specified
|
||||
`b`: The number of decimal places to round to
|
||||
`X`: The type of format to use, and the end of the specifier. Use `d` for integer base 10 (decimal) representation, `f` for fixed point decimal, and `e` for exponential notation
|
||||
# Standard library
|
@ -8,12 +8,13 @@ d. `1e-06 `
|
||||
```c
|
||||
float x = 0.12345;
|
||||
// a
|
||||
printf("%-8.1f", x);
|
||||
printf("%-8.1e", x);
|
||||
// b
|
||||
printf("%10.6f", x);
|
||||
printf("%10.6e", x);
|
||||
// c
|
||||
printf("%8.3f", x);
|
||||
// d
|
||||
printf("%-6.0g", x);
|
||||
printf("%-6.0f", x);
|
||||
```
|
||||
c.
|
||||
|
||||
# 3.
|
||||
|
Loading…
Reference in New Issue
Block a user