WeBWorK Main Forum

Preventing default Scientific notation displays in solutions

Preventing default Scientific notation displays in solutions

by tim Payer -
Number of replies: 4

Can anyone tell me how to turn off the default Scientific displays in the solution displays? I have 4 digit integers in the notation and the occasional "-1.15e + 03" display for a number such as "-1152" adds to the confusion when first semester students are reading the solutions.

The variables are math objects, created with "Compute("")" commands.

If I bypass the math object declaration and use "sprintf(%d, $fx12)" instead, this does convert the values to integers. But then a second problem results in that the question marks that are placed between the terms then display. These question marks should display to their respective +/- signs when applied to Math objects. But when Math objects are not used those questions marks are displayed instead of the associated sign for each term.


Any ideas for this?

Thanks for any consideration.

In reply to tim Payer

Re: Preventing default Scientific notation displays in solutions

by Danny Glin -
Here are some observations gleaned from trial and error.  I can't tell you why these things are happening, but they may point someone with a deeper knowledge of PG in the right direction.

I'm not at all familiar with the question mark notation, but for some reason it seems to be messing with the display format of MathObject Reals.

All of the following examples use

$fx12 = Compute("567");
$fx22 = Compute("-1200");

  • [``[$fx22]``] displays as -1152, so without the question mark scientific notation is not invoked
  • [``[$fx12]?[$fx22]``] displays as 567 - 1.15e + 03, as you experienced
  • [``[$fx12]+[$fx22]``] displays as 567 + -1152, which I'm assuming is what you're trying to avoid.
  • [``[$fx12->value]+[$fx22->value]``] displays as 567-1152, which I believe is your desired output.
For some reason when adding two perl reals PGML replaces the addition of a negative with a subtraction, but not when adding two MathObjects.  This may be by design, since MathObjects formulas have the reduce method to simplify such things, but I wasn't able to find a way to use the reduce method to replace "+-" with "-" without completely simplifying the constant.

It's possible that what you've described is a bug in the question mark notation, or it's possible that the question mark notation was never fully implemented.

In reply to Danny Glin

Re: Preventing default Scientific notation displays in solutions

by tim Payer -

Thanks for looking into this Danny.

I suppose the third example with the doubling of signs is the least problematic. It is too bad that there is not another option for handling a change in signs.


In reply to tim Payer

Re: Preventing default Scientific notation displays in solutions

by Andras Balogh -

Can you please remind me why the need for Compute()?

$f2 = random(500,600);
$f3 = random(-1200,-1100);

[``[$f2]+[$f3]``] seems to work correctly.


In reply to Andras Balogh

Re: Preventing default Scientific notation displays in solutions

by tim Payer -

Hi Andras,


The point of the Compute(" ") command was that there was actually three terms in the original code block that had to be calculated. Plus for those question marks to work as default +/- signs the variable has to be a math object. But I did try your "random" designation of the variable just to experiment. Unfortunately the questions marks no longer work as default +/- signs.

But now it appears that if I just use "+" signs instead that the correct sign does display for each term.

Those Question marks were borrowed from some older code blocks and it seems now they are not necessary.


Sorry for all the trouble!


Tim