This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Input and Output / Number Formatting  /
PaddedForm

  • PaddedForm[ expr , n ] prints with all numbers in expr padded to leave room for a total of n digits.
  • PaddedForm[ expr , n , f ] prints with approximate real numbers having exactly f digits to the right of the decimal point.
  • By default, PaddedForm pads with spaces on the left to leave room for n digits.
  • PaddedForm pads with zeros on the right in approximate real numbers.
  • The length n specified in PaddedForm counts only digits, and not signs, breaks between digits, and so on.
  • PaddedForm takes the same options as NumberForm, but with some defaults different.
  • You can use PaddedForm to align columns of numbers.
  • PaddedForm acts as a "wrapper", which affects printing, but not evaluation.
  • See the Mathematica book: Section 2.8.7.
  • See also: ColumnForm, TableForm.

    Further Examples

    This pads with spaces to make room for up to 7 digits in each integer.

    In[1]:=

    Out[1]//PaddedForm=

    This creates a column of integers.

    In[2]:=

    Out[2]//PaddedForm=

    This prints each number with room for a total of 7 digits, and with 4 digits to the right of the decimal point.

    In[3]:=

    Out[3]//PaddedForm=

    If you set the option SignPadding -> True, Mathematica will insert leading spaces after the sign.

    In[4]:=

    Out[4]//PaddedForm=

    Only the mantissa portion is aligned when scientific notation is used.

    In[5]:=

    Out[5]//PaddedForm=

    This uses spaces instead of zeros for padding on the right.

    In[6]:=

    Out[6]//PaddedForm=