Difference between revisions of "FormattingDecimals"
m |
m |
||
Line 50: | Line 50: | ||
</p> |
</p> |
||
<p> |
<p> |
||
− | Note: If we load <code>MathObjects.pl</code>, then |
+ | Note: If we load <code>MathObjects.pl</code>, then <code>log</code> and <code>ln</code> are both defined to be the natural logarithm (base e, not base 10). If we had loaded the older <code>PGauxiliaryFunctions.pl</code> macro instead, then <code>ln</code> would be undefined and <code>log</code> would be defined as the natural logarithm (base e, not base 10). |
</p> |
</p> |
||
</td> |
</td> |
Revision as of 14:07, 16 January 2010
Formatting Decimals: PG Code Snippet
We show how to format decimals for display in PG problems. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.
PG problem file | Explanation |
---|---|
loadMacros("PGstandard.pl","MathObjects.pl"); |
Initialization: Standard. |
$b = random(3,7,1); # log is natural log, and ln is also natural log $a = sprintf("%0.3f", log($b)/log(10) ); |
Setup:
Use perl's
Note: If we load |
BEGIN_TEXT \( $a = \) \{ ans_rule(20) \} END_TEXT |
Main Text: Display the formatted number. |
ANS( $a->cmp() ); |
Answer Evaluation: Standard. |