12.07.2015 Views

2.7.5 Output Formats for Numbers

2.7.5 Output Formats for Numbers

2.7.5 Output Formats for Numbers

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.7 Textual <strong>Output</strong> 411This creates a column of integers. In[17]:= PaddedForm[ColumnForm[{456, 12345, 12}], 7]Out[17]//PaddedForm= 4561234512This prints each number with room <strong>for</strong> atotal of 7 digits, and with 4 digits to theright of the decimal point.In NumberForm, the 7 specifies themaximum precision, but does not makeMathematica pad with spaces.If you set the optionSignPadding->True, Mathematica willinsert leading spaces after the sign.Only the mantissa portion is alignedwhen scientific notation is used.In[18]:= PaddedForm[{-6.7, 6.888, 6.99999}, {7, 4}]Out[18]//PaddedForm= { -6.7000, 6.8880, 7.0000}In[19]:= NumberForm[{-6.7, 6.888, 6.99999}, {7, 4}]Out[19]//NumberForm= {-6.7, 6.888, 7.}In[20]:= PaddedForm[{-6.7, 6.888, 6.99999}, {7, 4},SignPadding->True]Out[20]//PaddedForm= {- 6.7000, 6.8880, 7.0000}In[21]:= PaddedForm[ColumnForm[{6.7 10^8, 48.7, -2.3 10^-16}], {4, 2}]8Out[21]//PaddedForm= 6.70 1048.70-16-2.30 10With the default setting <strong>for</strong> the option NumberPadding, bothNumberForm and PaddedForm inserttrailing zeros when they pad a number on the right. You can use spaces <strong>for</strong> padding on both the leftand the right by setting NumberPadding -> {" ", " "}.This uses spaces instead of zeros <strong>for</strong>padding on the right.In[22]:= PaddedForm[{-6.7, 6.888, 6.99999}, {7, 4},NumberPadding -> {" ", " "}]Out[22]//PaddedForm= { -6.7 , 6.888 , 7. }BaseForm[expr, b]print with all numbers given in base bPrinting numbers in other bases.This prints a number in base 2. In[23]:= BaseForm[2342424, 2]Out[23]//BaseForm= 10001110111110000110002In bases higher than 10, letters are used<strong>for</strong> the extra digits.In[24]:= BaseForm[242345341, 16]Out[24]//BaseForm= e71e57d16BaseForm also works with approximatereal numbers.In[25]:= BaseForm[2.3, 2]Out[25]//BaseForm= 10.01012Web sample page from The Mathematica Book, Second Edition, by Stephen Wolfram, published by Addison-Wesley Publishing Company (hardcoverISBN 0-201-51502-4; softcover ISBN 0-201-51507-5). To order Mathematica or this book contact Wolfram Research: info@wolfram.com;http://www.wolfram.com/; 1-800-441-6284.© 1991 Wolfram Research, Inc. Permission is hereby granted <strong>for</strong> web users to make one paper copy of this page <strong>for</strong> their personal use. Further reproduction,or any copying of machine-readable files (including this one) to any server computer, is strictly prohibited.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!