FormattingDecimals
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. |
$a = random(3,7,1); # log is natural log, and ln is also natural log $b = sprintf("%0.3f", log($a)/log(10) ); |
Setup:
Use perl's We used the logarithm change of base formula log10(a) = log(a) / log(10) = ln(a) / ln(10) to get a logarithm base 10.
Note: If we load |
BEGIN_TEXT \( $b = \) \{ ans_rule(20) \} END_TEXT |
Main Text: Display the formatted number. |
ANS( $b->cmp() ); |
Answer Evaluation: Standard. |