I would like to suppress trailing zeros in a print statement. For example, I would like this:
x = { 1.2345, 5.2, 9.86 }; print x;
to return:
1.2345 5.2 9.86
1 Answer
0
accepted
You can accomplish this with the format statement. You need to pass it the flag /rz. The 'r' tells GAUSS to right-justify the print statement and the 'z' tells GAUSS to display whichever is more compact, decimal or scientific notation and to suppress trailing zeros.
format /rz; x = { 1.2345, 5.2, 9.86 }; print x;
will return the desired output:
1.2345 5.2 9.86
The format statement can also take inputs for the width which to print each number and the number of digits to print. For example:
format /rz 10,2; x = { 1.2345, 5.2, 9.86 }; print x;
will display up to 2 digits and the final digit will be 10 spaces to the right of the left margin:
1.2 5.2 9.9
Whereas:
format /rz 8,3; x = { 1.2345, 5.2, 9.86 }; print x;
will display up to 3 digits with the final digit 8 spaces from the left margin:
1.23 5.2 9.86
Your Answer
1 Answer
You can accomplish this with the format statement. You need to pass it the flag /rz. The 'r' tells GAUSS to right-justify the print statement and the 'z' tells GAUSS to display whichever is more compact, decimal or scientific notation and to suppress trailing zeros.
format /rz; x = { 1.2345, 5.2, 9.86 }; print x;
will return the desired output:
1.2345 5.2 9.86
The format statement can also take inputs for the width which to print each number and the number of digits to print. For example:
format /rz 10,2; x = { 1.2345, 5.2, 9.86 }; print x;
will display up to 2 digits and the final digit will be 10 spaces to the right of the left margin:
1.2 5.2 9.9
Whereas:
format /rz 8,3; x = { 1.2345, 5.2, 9.86 }; print x;
will display up to 3 digits with the final digit 8 spaces from the left margin:
1.23 5.2 9.86