Precision numbers...

User ForumPrecision numbers...
monarcha asked 3 years ago

Hello, with the following code :

a = rndn(100,1);
print meanc(a-meanc(a));

returns something like :


What should I do to get 0 ???


Guillaume Monarcha

2 Answers
monarcha answered 3 years ago


aptech Staff answered 3 years ago

You change the format of your print statements by using the format command. Here is a basic example:

a = rndn(100,1);

format /rd 8,3;
print meanc(a - meanc(a));

This will return:


The first input to format, in this case /rd, tells GAUSS to:

  1. r - right format the printed output
  2. d - print the data as a decimal

The second input to format, in this case 8,3, tells GAUSS to:

  1. 8 - give each printed number enough space for 8 characters
  2. 3 - print out 3 decimal places
  3. If you wanted to print numbers that were left formatted using scientific notation rather than decimal format and wanted to print 4 decimals, you could enter:

    format /le 8,4;
    print meanc(a - meanc(a));

    This will return something like:


    Besides the d and e options, you can also use the z option. This will use either decimal or scientific notation, whichever is more concise. It will also suppress trailing zeros. Here is a link to another post describing this.