WeBWorK Main Forum

display precision in Solution computation

display precision in Solution computation

by Joel Trussell -
Number of replies: 2
IN the TEXT part of the problem the values display with 4-6 decimals, Likewise in the answer check. However, when we display the solution, the results display 15 digits, e.g.
B=7/52=0.134615384615385." role="presentation">B=7/52=0.134615384615385.
the code is

How do I get this display to limit the number of decimals?
The code is
To find the particular solution, we know the form of the particular solution is the same as that of the driving function. In this case, it is a constant, \( v_p(t) = B \). We differentiate the particular solution as needed and substitute into the differential equation. Since \( \dot{v}_p(t) = \ddot{v}_p(t) = 0\), we have the equation, \( $c v_p(t) = $c B = $A.\) We solve for \( B \) to obtain \( B = $A/$c = $B.\)
B=7/52=0.134615384615385." role="presentation">
In reply to Joel Trussell

Re: display precision in Solution computation

by Alex Jordan -
If you see that many decimals, you are probably displaying a "pure" perl scalar real.

If you see something trimmed to about 6 decimals, you are probably seeing a MathObject Real.

My guess is that if you look closely at the two variables used in the two places, they are not actually the same thing. Or there is a reassignment of that variable in between.

Here is some example code:

$b = 7/52;
# $b is now a perl sclalar real with value 0.134615384615385...
# It will display as 0.134615384615385

$B = Compute(7/52);
# $B is a MathObject.
# Compute will recognize to make it a Real, as opposed to say a Formula.
# You could achieve essentially the same thing with:
# $B = Real(7/52);
# $B = Real("7/52");
# $B = Real($b);
# $B = Real("$b");
# $B = Compute("7/52");
# $B = Compute($b);
# $B = Compute("$b");
# although some of these would store a little extra information than others.
# While the information 0.134615384615385... is still stored within $B,
# the default display controls for MathObjects
# would only display this as 0.134615