You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,10 @@
2
2
3
3
All notable changes to the pyprintf project will be documented in this file.
4
4
5
+
## [0.0.6] - 2025-04-18
6
+
7
+
* Resolved an issue where the `E` (exponential) format specifier was not recognized by the parser.
8
+
5
9
## [0.0.5] - 2025-04-17
6
10
7
11
* Added support for uppercase `E` in scientific notation output for floating-point numbers through the `%E` format specifier (e.g., `1.234500E+02`), alongside the existing lowercase `e` format (`%e`).
Copy file name to clipboardExpand all lines: README.md
+78-43Lines changed: 78 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,49 +98,84 @@ The `sprintf` function uses placeholders within the format string (the first arg
98
98
99
99
### Optional Formatting Elements
100
100
101
-
These elements can appear in a placeholder in a specific order between the `%` and the type specifier.
102
-
103
-
1.**Argument Index (Positional Specifier)**:
104
-
***Syntax:** A number (starting from 1) followed by a `$` (e.g., `%2$s`).
105
-
***Description:** Explicitly selects which argument to use for the current placeholder. If omitted, arguments are used sequentially in the order they are provided to `sprintf`.
106
-
***Example:**`sprintf("%2$s, %1$s!", "Hello", "World")` will output `"World, Hello!"`.
107
-
108
-
2.**Sign Indicator**:
109
-
***Syntax:** A `+` character (e.g., `%+d`).
110
-
***Description:** Forces numeric values (integers and floats) to always display a sign, either `+` for positive numbers or `-` for negative numbers. By default, only negative numbers show a sign.
111
-
***Example:**`sprintf("%+d", 5)` will output `"+5"`, and `sprintf("%+d", -5)` will output `"-5"`.
112
-
113
-
3.**Padding Specifier**:
114
-
***Syntax:** Either a `0` or a single quote `'` followed by any character (e.g., `%05d`, `%'*5s`).
115
-
***Description:** Specifies the character used for padding the output to reach the desired width.
116
-
* Using `0` pads with leading zeros for numeric types.
117
-
* Using `'` followed by a character pads with that specific character.
118
-
***Examples:**
119
-
*`sprintf("%05d", 12)` will output `"00012"`.
120
-
*`sprintf("%'*5s", "abc")` will output `"**abc"`.
121
-
122
-
4.**Alignment**:
123
-
***Syntax:** A `-` character (e.g., `%-10s`).
124
-
***Description:** Aligns the output to the left within the specified field width. If the `-` is omitted, the output is right-aligned by default.
125
-
***Example:**`sprintf("%-10s", "hello")` will output `"hello "`, and `sprintf("%10s", "hello")` will output `" hello"`.
126
-
127
-
5.**Width**:
128
-
***Syntax:** A positive integer (e.g., `%10s`, `%5j`).
129
-
***Description:** Specifies the minimum number of characters to output. If the value to be formatted is shorter than the width, it will be padded (using the padding character and alignment). For the `j` (JSON) type, this number defines the indentation level (number of spaces).
130
-
***Examples:**
131
-
*`sprintf("%10s", "test")` will output `" test"`.
132
-
*`sprintf("%5j", { a: 1 })` will output `"{\n "a": 1\n}"`.
133
-
134
-
6.**Precision**:
135
-
***Syntax:** A period `.` followed by a non-negative integer (e.g., `%.2f`, `%.5g`, `%.10s`).
136
-
***Description:** Controls the precision of the output depending on the type specifier:
137
-
* For floating-point types (`e`, `f`): Specifies the number of digits to appear after the decimal point.
138
-
* For the `g` type: Specifies the number of significant digits.
139
-
* For the `s`, `t`, `T`, and `v` types: Specifies the maximum number of characters to output (truncates the string if it's longer).
140
-
***Examples:**
141
-
*`sprintf("%.2f", 3.14159)` will output `"3.14"`.
142
-
*`sprintf("%.5g", 123.45678)` will output `"123.46"`.
143
-
*`sprintf("%.5s", "This is a long string")` will output `"This "`.
101
+
The `sprintf` function supports a wide range of formatting options. Each placeholder can include optional modifiers to control how the corresponding value is displayed. Below are the supported options in the order they can appear in a format specifier:
102
+
103
+
**Argument Index (Positional Specifier)**
104
+
105
+
***Syntax:**`%<index>$<specifier>` (e.g., `%2$s`)
106
+
***Description:** Specifies which argument to insert at this position, starting from `1`. Useful when you want to change the order of values.
107
+
***Default:** If omitted, arguments are used in the order they appear.
108
+
***Example:**
109
+
110
+
```python
111
+
sprintf("%2$s, %1$s!", "Hello", "World") # will output "World, Hello!"
112
+
```
113
+
114
+
**Sign Indicator**
115
+
116
+
***Syntax:**`%+<specifier>` (e.g., `%+d`)
117
+
***Description:** Forces numeric output to always include a sign (`+` or `-`).
118
+
***Default:** Only negative numbers show a sign.
119
+
***Example:**
120
+
121
+
```python
122
+
sprintf("%+d", 5) # will output "+5"
123
+
sprintf("%+d", -5) # will output "-5"
124
+
```
125
+
126
+
**Padding Specifier**
127
+
128
+
* Syntax: `%0<width><specifier>` or `%'<char><width><specifier>` (e.g., `%05d`, `%'*5s`)
129
+
* Description: Defines the character used for padding.
130
+
*`0` pads numeric types with leading zeros.
131
+
*`'` followed by a character pads with that character.
0 commit comments