MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Printing numbers

  • To: mathgroup at
  • Subject: [mg54552] Re: Printing numbers
  • From: Bill Rowe <readnewsciv at>
  • Date: Tue, 22 Feb 2005 04:25:50 -0500 (EST)
  • Sender: owner-wri-mathgroup at

On 2/21/05 at 3:44 AM, stevebg at (Steve Gray) wrote:

>1. Can anyone tell me why these results are what they are? Neither
>answer is what I would expect, which is 10. The two strings are the
>same length.

>Print[StringLength[ToString[123.456789]], "   ",
>7    22

Look at the strings returned in each case. What you are seeing is the result of the default displays Mathematica uses. In the first example, Mathematica by default displays only three decimals to the right of the decimal point resulting in a seven character long string. In the second example, by default Mathematica displays the number in scientific form with 6 significant digits. Since the string form of this must include the exponent, the result is a longer string.

>2. Is there a simple, easily available or self-evident way to get
>numbers printed out such that the total  number of spaces occupied
>by the print before the decimal point is some fixed, user-specified
>amount, the number of spaces occupied after the decimal point is a
>different user-specified amount, and the number of spaces following
>the number is a third user-specified amount. 

Yes. Take a look at the documentation for PaddedForm and NumberForm. For example,

(PaddedForm[#1, {8, 3}] & ) /@ {345.678, 34.5678, -345.678}
{PaddedForm[345.678, {8, 3}], PaddedForm[34.5678, 
   {8, 3}], PaddedForm[-345.678, {8, 3}]}
(StringLength[ToString[#1]] & ) /@ %
{10, 10, 10}
To reply via email subtract one hundred and four

  • Prev by Date: Re: problems plotting a derivative
  • Next by Date: Re: problems plotting a derivative
  • Previous by thread: Re: Printing numbers
  • Next by thread: Re: Printing numbers