WeBWorK Main Forum

Displaying small decimals

Displaying small decimals

by Kris Watkins -
Number of replies: 1

In my code I'm trying to display the decimal .00001 but it keeps getting displayed as 1e -05 in the preview screen. Do you know how to fix this?

DOCUMENT();      

loadMacros(
    "PGstandard.pl",
  "MathObjects.pl",
  "contextFraction.pl",
  "parserFormulaUpToConstant.pl",
  "PGcourse.pl"
);

TEXT(beginproblem());

do
{
    $a = random(2, 9);
    $b = random(2, 9);
}
until (
    ($b < $a)
    );

Context("Numeric")->flags->set(
    reduceConstants => 0);
#$c = list_random(.001, .0001, .00001, .01);
$c = .00001;


Context()->texStrings;
BEGIN_TEXT
If we want to approximate \( \displaystyle f(x) = \ln($a - $b x)\) with a \( \displaystyle n\)-th degree Taylor polynomial, then what is the smallest \(\displaystyle n \) that will give us an error less than \( \displaystyle $c\)
END_TEXT
Context()->normalStrings;



ENDDOCUMENT();


In reply to Kris Watkins

Re: Displaying small decimals

by Nathan Wallach -

Have a look at the number formats section of https://webwork.maa.org/wiki/Modifying_Contexts_(advanced) which should probably help. However, you may be better off just defining $c as a string like "0.00001".

$c = list_random(".001", ".0001", ".00001", ".01");

Also of potential interest is using Perl's sprintf: