Center Integers
Center-align integers in a fixed-width field with customizable padding characters. Supports bulk multiline input with instant formatting.
About
Columnar data becomes unreadable the moment integers of varying digit counts sit flush-left or flush-right in a fixed-width field. A 7-digit value next to a 2-digit value creates visual noise that slows pattern recognition in log files, console output, and monospaced reports. This tool centers each integer within a uniform field width W, distributing padding characters symmetrically around the digits. The field width defaults to the longest integer in the batch, or you can lock it manually. Negative signs are preserved as part of the digit string before centering. The tool handles edge cases: empty lines are passed through unchanged, non-integer lines are flagged, and a width smaller than the longest integer triggers a warning rather than silent truncation.
Centering is defined by left-pad length L = floor((W โ D) รท 2) where D is the character length of the integer including its sign. The remaining padding fills the right side. This left-bias convention matches most typographic centering standards. Pro tip: when pasting into HTML or Markdown tables, use a non-breaking space ( ) as your pad character to prevent whitespace collapse.
Formulas
Each integer string of character length D (including sign) is centered within a field of width W. The total padding needed is P = W โ D. This padding is split into left and right portions:
Where W = field width (auto-detected as max(D1, D2, โฆ, Dn) or manually set), D = character length of the integer string, L = left padding count, R = right padding count, c = padding character (space, zero, dot, or custom). When W โ D is odd, the extra character goes to the right side (left-bias centering). If D โฅ W, the integer is output unchanged with no padding.
Reference Data
| Input Integer | Digit Length (D) | Field Width (W) | Left Pad (L) | Right Pad (R) | Centered Output (pad = ยท) |
|---|---|---|---|---|---|
| 5 | 1 | 7 | 3 | 3 | ยทยทยท5ยทยทยท |
| 42 | 2 | 7 | 2 | 3 | ยทยท42ยทยทยท |
| -8 | 2 | 7 | 2 | 3 | ยทยท-8ยทยทยท |
| 100 | 3 | 7 | 2 | 2 | ยทยท100ยทยท |
| -1024 | 5 | 7 | 1 | 1 | ยท-1024ยท |
| 0 | 1 | 7 | 3 | 3 | ยทยทยท0ยทยทยท |
| 9999999 | 7 | 7 | 0 | 0 | 9999999 |
| -3 | 2 | 10 | 4 | 4 | ยทยทยทยท-3ยทยทยทยท |
| 256 | 3 | 10 | 3 | 4 | ยทยทยท256ยทยทยทยท |
| 12345 | 5 | 10 | 2 | 3 | ยทยท12345ยทยทยท |
| -99 | 3 | 5 | 1 | 1 | ยท-99ยท |
| 7 | 1 | 1 | 0 | 0 | 7 |
| +42 | 3 | 7 | 2 | 2 | ยทยท+42ยทยท |
| 00007 | 5 | 9 | 2 | 2 | ยทยท00007ยทยท |
| -000123 | 7 | 11 | 2 | 2 | ยทยท-000123ยทยท |
Frequently Asked Questions
str.center() and most typographic systems..ยท, pre-process the output by replacing single-character pads with your pattern externally.