I am looking in the NPL and getting many varying codes for the answer-checker for finance math problems. MY GOAL: for students to enter answers like 121.22 (or even $121.22) when the numerical answer to a finance math problem is 121.2161241 for example.
When I look through the NPL examples, I see three types of code:
1. ANS(num_cmp($ans, format => '%0.2f', tol => .01));
This does what I need, but I am not sure what the %0.2f means. Also just after the preamble following the TEXT(beginproblem());, I see:
Context()->flags->set( tolerance=>0, tolType=>'absolute' );
I am wondering if the latter is needed (i.e., does the tol=>.01 in the former override the tolerance=>0 in the latter?).
2. ANS( Compute($ans)->cmp() );
This does NOT do what I need, because in the answer checker it displays answers like 121.2161241 as the correct answer, and I prefer the answer to have only 2 decimal digits of accuracy since the answer is a dollar/cents amount.
3. Unlike the two examples, I have seen code that has "contextCurrency.pl" in the preamble for the macros, and then code like:
$ans = Currency("$an");
And that is followed by the following in the answer checker by:
So I am a little (perhaps 'a lot') confused here by the varying examples in the NPL. Any advice is very welcome.
Thanks much in advance,
When I taught business math (in a trades/technology setting) it was a scramble and I never got around to such refinements.
However it seems if you set the answer (at the start) to the rounded or truncated value you would avoid the trailing decimals.
$answer = int(100*$answer)/100 ; # to round
$answer = int(100*$answer -0.5)/100 ; # to truncate a value
On another topic -
Attached are the problems I used; some of the multiple choice/match questions may be proprietary to the textbook? The rest seems generic. They also push the use of the HP- 10bII financial calculator - oh and Canadian examples.
The quick look can be found at http://www.teabun.ca/webwork2/MA2400_sample
Log in as guest.
The attachment extracts to Assignment01, Assignment02, ... Assignment10
The above is wrong - int will generally (?) truncate.
Perhaps it would be best to use the "round" function loaded with PGstandard
Years ago Fortran IV (with WATFIV) we rounded with int(x+0.5)
Then a new version was installed and the rounding was done automatically.
I thought this to be a very progressive at the time; I guess perl has regressed.