Printf Format Tester

Test printf and sprintf format strings with your own arguments and see the output as you type. Each placeholder is broken down into its flags, width, precision, and type.

Updated
Runs in your browser. Your data is not uploaded.
Style
Output

    
Placeholders in the format string
PlaceholderArgumentFlagsWidthPrecisionResult

How to use the Printf Format Tester

  1. Choose the Style: C printf or PHP sprintf.
  2. Type the Format string, such as %-10s|%08.3f, and put one value per line in Arguments.
  3. Read the Output and the table that explains each placeholder and the argument it used.

How it works

A placeholder has the form %[argnum$][flags][width][.precision]type.

  • Flags: - aligns left, + always shows the sign, a space puts a space before positive numbers, 0 pads with zeros, and # adds 0x or 0 prefixes in C. In PHP, 'c pads with the character c.
  • Width is the minimum length. Shorter values are padded.
  • Precision is the number of decimals for f and e, the number of significant digits for g, and the maximum length for s.
  • %2$s uses the second argument, whatever its position. %% prints a percent sign.
  • Arguments are converted to the type the placeholder expects: %d with 3.9 prints 3.

Examples

  • %05.1f with 3.14159 gives 003.1.
  • %-8s| with abc gives abc |.
  • %+d with 42 gives +42.
  • %x with 255 gives ff, and %#X in C gives 0XFF.
  • %.2e with 12345.678 gives 1.23e+04.
  • PHP: %'*10s with php gives *******php, and %b with 5 gives 101.
  • %2$s %1$s with world and hello gives hello world.

Limitations

  • C length modifiers such as l, ll, and h are accepted and ignored, because the numbers here are not limited to a fixed size. Overflow behaviour isn't simulated.
  • %n and %p are not supported, because they depend on memory addresses.
  • Integers beyond ±9,007,199,254,740,991 lose precision in the browser.
  • Locale-specific formatting, such as a comma as the decimal separator, is not applied.

Frequently asked questions

What is the difference between printf and sprintf?

printf prints the formatted text straight away. sprintf returns it as a string. The format rules are the same.

How do I print a percent sign?

Write %%. A single % starts a placeholder.

Why does %d show 3 for 3.9?

%d formats an integer, so the decimal part is dropped, not rounded. Use %.0f to round instead.

Does this work for Python, Go, or Java?

Their % style follows the same core rules, so most format strings behave the same. Python's {} format and f-strings use a different syntax.

Often used together with the Printf Format Tester.

  • PHP Formatter

    Re-indents PHP code safely without touching strings, comments, or inline HTML.

  • Regex Tester

    Highlights regex matches live, lists capture groups and offsets, and previews replacements.