User Rating 0.0 β˜…β˜…β˜…β˜…β˜…
Total Usage 0 times
Enter the value you want to pad
Single character
Total characters (max 1000)
Presets:
Is this tool helpful?

Your feedback helps us improve.

β˜… β˜… β˜… β˜… β˜…

About

String padding errors cause silent data corruption in databases, CSV exports, and API payloads. A ZIP code of 7310 instead of 07310 routes mail to the wrong state. An invoice number missing its leading zeros breaks sort order across accounting systems. This tool applies deterministic character padding to any numeric string, letting you specify the fill character c, target width w, and alignment direction. It handles edge cases that naive implementations miss: inputs already exceeding target width are returned unchanged, and center-padding distributes the remainder with floor on the left and ceil on the right to maintain visual balance.

The tool preserves sign characters and decimal points as part of the input string. It does not interpret numeric value. This is intentional. Padding operates on the string representation, not the number. If you need to pad -42 to width 6 with zeros, the result is 00-42, not -00042. For sign-aware padding, pre-process by separating the sign before padding the magnitude.

pad number left pad zero padding string padding number formatting right pad center pad

Formulas

Padding computes the number of fill characters needed as the difference between the target width and the current string length, clamped to zero.

padding = max(0, w βˆ’ len(s))

For left-padding, all padding characters are prepended. For right-padding, all are appended. For center-padding, the distribution is:

left = floor(padding2)
right = ceil(padding2)

Where w is the desired total width, s is the input string, c is the pad character (single character), and len returns the string length. When len(s) β‰₯ w, the original string is returned unmodified.

Reference Data

Use CaseInputPad CharWidthDirectionResult
US ZIP Code731005Left07310
Invoice Number4208Left00000042
Binary Byte10108Left00000101
Hex Color CodeFF06Left0000FF
Fixed-Width Column99Space10Right99Β·Β·Β·Β·Β·Β·Β·Β·
Centered Label42-10Center----42----
Centered Odd Remainder7*6Center**7***
SSN Fragment5604Left0056
Already Full Width1234503Left12345
Decimal Price9.506Left0009.5
Batch ID3012Left000000000003
Table Separator100.8Right100.....
Empty Input(empty)04Left0000
Single Digit Year502Left05
Product SKU891010Left0000000891

Frequently Asked Questions

This tool performs string-level padding, not numeric-aware formatting. The minus sign is treated as an ordinary character within the string. If you need sign-aware zero-padding, strip the sign before padding, then re-prepend it. For example, separate "-" and "42", pad "42" to width 5 producing "00042", then concatenate to get "-00042".
The input is returned unchanged. The padding count formula is max(0, w βˆ’ len(s)). When len(s) β‰₯ w, the result is 0 fill characters. No truncation occurs. This is consistent with the behavior of padStart() and padEnd() in ECMAScript 2017+.
When the padding count is odd, the extra character goes to the right side. Specifically, the left side receives floor(padding / 2) characters and the right side receives ceil(padding / 2). For example, padding "7" to width 6 with "*" produces "**7***" - 2 on the left, 3 on the right.
No. The pad character field is restricted to a single character. Multi-character padding patterns introduce ambiguity when the remaining space is not evenly divisible by the pattern length. If you need repeating patterns, pad with a single character first, then find-and-replace in a text editor.
Yes. The target width is capped at 1000 characters. Creating strings beyond this length in a browser environment is technically possible, but serves no practical formatting purpose and risks UI rendering delays. Most real-world padding use cases (ZIP codes, invoice numbers, binary bytes) require widths under 64.
It works with any single Unicode character that JavaScript's String.length counts as 1. Most emoji are represented as surrogate pairs (length 2), so they will be rejected by the single-character validation. Standard accented characters (Γ©, Γ±, ΓΌ) work correctly as they are single code units in UTF-16.