vault backup: 2024-09-11 12:16:34

This commit is contained in:
zleyyij 2024-09-11 12:16:34 -06:00
parent 2a86cc053b
commit 4519740ea7
2 changed files with 15 additions and 5 deletions

View File

@ -31,3 +31,12 @@ A variable must be declared before it is assigned.
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------- | | --------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `%d` | Display an integer | | `%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

View File

@ -8,12 +8,13 @@ d. `1e-06 `
```c ```c
float x = 0.12345; float x = 0.12345;
// a // a
printf("%-8.1f", x); printf("%-8.1e", x);
// b // b
printf("%10.6f", x); printf("%10.6e", x);
// c // c
printf("%8.3f", x); printf("%8.3f", x);
// d // d
printf("%-6.0g", x); printf("%-6.0f", x);
``` ```
c.
# 3.