# Output Formats for Numbers

ScientificForm[expr] | print all numbers in scientific notation |

EngineeringForm[expr] | print all numbers in engineering notation (exponents divisible by 3) |

AccountingForm[expr] | print all numbers in standard accounting format |

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]//ScientificForm= | |

In[3]:= |

Out[3]//EngineeringForm= | |

In[4]:= |

Out[4]//AccountingForm= | |

NumberForm[expr,tot] | print at most tot digits of all approximate real numbers in expr |

ScientificForm[expr,tot] | use scientific notation with at most tot digits |

EngineeringForm[expr,tot] | use engineering notation with at most tot digits |

Controlling the printed precision of real numbers.

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]//NumberForm= | |

In[7]:= |

Out[7]//EngineeringForm= | |

option name | default value | |

DigitBlock | Infinity | maximum length of blocks of digits between breaks |

NumberSeparator | {","," "} | strings to insert at breaks between blocks of digits to the left and right of a decimal point |

NumberPoint | "." | string to use for a decimal point |

NumberMultiplier | "∖[Times]" | string to use for the multiplication sign in scientific notation |

NumberSigns | {"-",""} | strings to use for signs of negative and positive numbers |

NumberPadding | {"",""} | strings to use for padding on the left and right |

SignPadding | False | whether to insert padding after the sign |

NumberFormat | Automatic | function to generate final format of number |

ExponentFunction | Automatic | function to determine the exponent to use |

Options for number formatting.

All the options in the table except the last one apply to both integers and approximate real numbers.

All the options can be used in any of the functions NumberForm, ScientificForm, EngineeringForm, and AccountingForm. In fact, you can in principle reproduce the behavior of any one of these functions simply by giving appropriate option settings in one of the others. The default option settings listed in the table are those for NumberForm.

In[8]:= |

Out[8]//NumberForm= | |

In[9]:= |

Out[9]//NumberForm= | |

In[10]:= |

Out[10]//NumberForm= | |

When the Wolfram Language prints an approximate real number, it has to choose whether scientific notation should be used, and if so, how many digits should appear to the left of the decimal point. What the Wolfram Language does is first to find out what the exponent would be if scientific notation were used, and one digit were given to the left of the decimal point. Then it takes this exponent, and applies any function given as the setting for the option ExponentFunction. This function should return the actual exponent to be used, or Null if scientific notation should not be used.

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]//NumberForm= | |

In[13]:= |

Out[13]//NumberForm= | |

Having determined what the mantissa and exponent for a number should be, the final step is to assemble these into the object to print. The option NumberFormat allows you to give an arbitrary function which specifies the print form for the number. The function takes as arguments three strings: the mantissa, the base, and the exponent for the number. If there is no exponent, it is given as .

In[14]:= |

Out[14]//NumberForm= | |

PaddedForm[expr,tot] | print with all numbers having room for tot digits, padding with leading spaces if necessary |

PaddedForm[expr,{tot,frac}] | print with all numbers having room for tot digits, with exactly frac digits to the right of the decimal point |

NumberForm[expr,{tot,frac}] | print with all numbers having at most tot digits, exactly frac of them to the right of the decimal point |

Column[{expr_{1},expr_{2},…}] | print with the left aligned in a column |

Controlling the alignment of numbers in output.

Whenever you print a collection of numbers in a column or some other definite arrangement, you typically need to be able to align the numbers in a definite way. Usually you want all the numbers to be set up so that the digit corresponding to a particular power of 10 always appears at the same position within the region used to print a number.

You can change the positions of digits in the printed form of a number by "padding" it in various ways. You can pad on the right, typically adding zeros somewhere after the decimal. Or you can pad on the left, typically inserting spaces in place of leading zeros.

In[16]:= |

Out[16]//PaddedForm= | |

In[17]:= |

Out[17]//PaddedForm= | |

In[18]:= |

Out[18]//PaddedForm= | |

In[19]:= |

Out[19]//NumberForm= | |

*after*the sign.

In[20]:= |

Out[20]//PaddedForm= | |

In[21]:= |

Out[21]//PaddedForm= | |

With the default setting for the option NumberPadding, both NumberForm and PaddedForm insert trailing zeros when they pad a number on the right. You can use spaces for padding on both the left and the right by setting NumberPadding->{" "," "}.

In[22]:= |

Out[22]//PaddedForm= | |

BaseForm[expr,b] | print with all numbers given in base b |

Printing numbers in other bases.

In[23]:= |

Out[23]//BaseForm= | |

In[24]:= |

Out[24]//BaseForm= | |

In[25]:= |

Out[25]//BaseForm= | |

In[26]:= |

Out[26]//BaseForm= | |

"Digits in Numbers" discusses how to enter numbers in arbitrary bases, and also how to get lists of the digits in a number.