PREP 2015 Question Authoring - Archived

number format control

Re: number format control

by Davide Cervone -
Number of replies: 0
I'd say use
    $vx1 = sprintf("%.2f",$vx + $vx*non_zero_random(-0.10,0.10,0.01));
to get the 2 digits that you want. You could alter the display format from the default of "%g" to "%.2f", but the results might be different since you would just be rounding the final answer.

I don't know of a way to force computations to be restricted to a certain number of digits, but you can force intermediate results to 2 digits along the way using sprintf() as above.