<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, How to format numbers and save memory?</title>
    <link>http://www.mapleprimes.com/questions/40744-How-To-Format-Numbers-And-Save-Memory</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Fri, 12 Jun 2026 00:37:30 GMT</lastBuildDate>
    <pubDate>Fri, 12 Jun 2026 00:37:30 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, How to format numbers and save memory?</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, How to format numbers and save memory?</title>
      <link>http://www.mapleprimes.com/questions/40744-How-To-Format-Numbers-And-Save-Memory</link>
    </image>
    <item>
      <title>Formatted Printing</title>
      <link>http://www.mapleprimes.com/questions/40744-How-To-Format-Numbers-And-Save-Memory?ref=Feed:MaplePrimes:How to format numbers and save memory?:Comments#answer75411</link>
      <itunes:summary>Jean,

One way to do this is with printf (formatted printing). The syntax closely parallels that for C. For the case you give in your original post, here is what I would suggest:
&lt;pre&gt;
for i from 1 to 10 do
  printf( "%3d %3d %5.3f\n", i, i^2, i^(1/3) );
end do;
  1   1 1.000
  2   4 1.260
  3   9 1.442
  4  16 1.587
  5  25 1.710
  6  36 1.817
  7  49 1.913
  8  64 2.000
  9  81 2.080
 10 100 2.154
&lt;/pre&gt;

Note that this only generates output. There is no matrix of results. This makes this more efficient than your method, but not if you want to have the matrix of values for other purposes.

See the online help ?printf for complete details about printf and the different formatting options that are supported.

With fprintf you can print results directly to a file. sprintf and nprintf produce strings and names, respectively.

I hope this is helpful,

Doug
&lt;pre&gt;
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
&lt;/pre&gt;</itunes:summary>
      <description>Jean,

One way to do this is with printf (formatted printing). The syntax closely parallels that for C. For the case you give in your original post, here is what I would suggest:
&lt;pre&gt;
for i from 1 to 10 do
  printf( "%3d %3d %5.3f\n", i, i^2, i^(1/3) );
end do;
  1   1 1.000
  2   4 1.260
  3   9 1.442
  4  16 1.587
  5  25 1.710
  6  36 1.817
  7  49 1.913
  8  64 2.000
  9  81 2.080
 10 100 2.154
&lt;/pre&gt;

Note that this only generates output. There is no matrix of results. This makes this more efficient than your method, but not if you want to have the matrix of values for other purposes.

See the online help ?printf for complete details about printf and the different formatting options that are supported.

With fprintf you can print results directly to a file. sprintf and nprintf produce strings and names, respectively.

I hope this is helpful,

Doug
&lt;pre&gt;
---------------------------------------------------------------------
Douglas B. Meade
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu/~meade/
&lt;/pre&gt;</description>
      <guid>75411</guid>
      <pubDate>Fri, 05 Oct 2007 20:36:39 Z</pubDate>
      <itunes:author>Doug Meade</itunes:author>
      <author>Doug Meade</author>
    </item>
    <item>
      <title>Format numbers</title>
      <link>http://www.mapleprimes.com/questions/40744-How-To-Format-Numbers-And-Save-Memory?ref=Feed:MaplePrimes:How to format numbers and save memory?:Comments#answer75410</link>
      <itunes:summary>Hello,

A := array(1..10);
Digits:=4:
for i from 1 to 10
etc.</itunes:summary>
      <description>Hello,

A := array(1..10);
Digits:=4:
for i from 1 to 10
etc.</description>
      <guid>75410</guid>
      <pubDate>Fri, 05 Oct 2007 22:28:02 Z</pubDate>
      <itunes:author>SandorSzabo</itunes:author>
      <author>SandorSzabo</author>
    </item>
    <item>
      <title>Matrix</title>
      <link>http://www.mapleprimes.com/questions/40744-How-To-Format-Numbers-And-Save-Memory?ref=Feed:MaplePrimes:How to format numbers and save memory?:Comments#answer75409</link>
      <itunes:summary>Jean,

Another way of achieving only 3 decimal places is to use interface(displayprecision=3). See the example below.

You mentioned array and matrix. In Maple these are different objects, and although you can continue to use them, the newer versions of these - Array and Matrix - are more efficient. Please see ?Array and ?Matrix.

Here are two examples of Matrices filled with the initial values that you specified. If you want to see the contents of B, right click on the Matrix placeholder in the output and select Browse.

restart;
interface(displayprecision=3):
f := (i,j) -&gt; `if`(j&lt;=2,i^j,evalf(i^(1/j))):
A := Matrix(1..10,1..3,f);
B := Matrix(1..1000,1..3,f);

Hope this helps.

J. Tarr</itunes:summary>
      <description>Jean,

Another way of achieving only 3 decimal places is to use interface(displayprecision=3). See the example below.

You mentioned array and matrix. In Maple these are different objects, and although you can continue to use them, the newer versions of these - Array and Matrix - are more efficient. Please see ?Array and ?Matrix.

Here are two examples of Matrices filled with the initial values that you specified. If you want to see the contents of B, right click on the Matrix placeholder in the output and select Browse.

restart;
interface(displayprecision=3):
f := (i,j) -&gt; `if`(j&lt;=2,i^j,evalf(i^(1/j))):
A := Matrix(1..10,1..3,f);
B := Matrix(1..1000,1..3,f);

Hope this helps.

J. Tarr</description>
      <guid>75409</guid>
      <pubDate>Fri, 05 Oct 2007 23:17:23 Z</pubDate>
      <itunes:author>Mariner</itunes:author>
      <author>Mariner</author>
    </item>
    <item>
      <title>Thanks a lot!!</title>
      <link>http://www.mapleprimes.com/questions/40744-How-To-Format-Numbers-And-Save-Memory?ref=Feed:MaplePrimes:How to format numbers and save memory?:Comments#answer75405</link>
      <itunes:summary>Dear Doug, Sandor, J. Tarr,

Thanks a lot for the explantion.. your posts
are more than sufficient to deal with my problem.

Jean</itunes:summary>
      <description>Dear Doug, Sandor, J. Tarr,

Thanks a lot for the explantion.. your posts
are more than sufficient to deal with my problem.

Jean</description>
      <guid>75405</guid>
      <pubDate>Sat, 06 Oct 2007 18:56:53 Z</pubDate>
      <itunes:author>Jean</itunes:author>
      <author>Jean</author>
    </item>
  </channel>
</rss>