Significant figures

Re: Significant figures

by Dominique Bauer -
Number of replies: 4
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Well, the reason toPrecision() uses the exponential format in the example

Number=123.45;
Number.toPrecision(2)   // returns 1.2e+2

is to show clearly the two significant figures. Whereas with 120, the number of significant figures is not clear since it could be 2 or 3.

My apologies, toPrecision() is fine.

Yet, in many cases we would like to keep the decimal format, and 120 would be preferred over 1.2e+2.

In reply to Dominique Bauer

Re: Significant figures

by Jean-Michel Védrine -

Hello Dominique,

Don't you think it would an interesting addition to add a toprecision($number, $precision) function to variables.php so that it could be used in formulas questions ? Of course that function would return a string not a number to be able to display the right number of trailing zeros.

This would not require a lot of work. In fact just to translate your code to php.

My idea in adding the poly function was that if formulas already has a lot of math functions it somewhat miss some functions to ease the display of questions. The toprecision function seems to be a nice addition in the same area.

In reply to Jean-Michel Védrine

Re: Significant figures

by Dave Morgan -

I am new to Moodle and formulas and really miss the stringified value of number with extra 0s at the end of the mantissa. An input of 4.00 is often better than 4.

And significant digits is very important. Also, if answers are to three significant digits, then an answer with 1 as the first non zero entry should (?) have an extra significant digit displayed: 123.4, 23.4.

In reply to Dave Morgan

Re: Significant figures

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Dave,

"Numbers starting with 1 should have an additional significant digit" is not a strict rule. However, it is a good way to improve the precision of the numbers.

If this rule is not applied, the precision of any number is between 0.1% (for example 99.9 ± 0.1 = 99.9 ± 0.1%) and 1% (for example 100 ± 1 = 100 ± 1%). If the rule is applied, the precision of any number is between 0.05% (for example 199.9 ± 0.1 = 199.9 ± 0.05%) and 0.5% (for example 200 ± 1 = 200 ± 0.5%).

Thus, by applying the rule, the precision of the numbers improves from ± 1% or better to ± 0.5% or better.

In reply to Jean-Michel Védrine

Re: Significant figures

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Jean-Michel,

I'm sorry I missed your post.

It would certainly be interesting to add a function to display the numbers with a given number of significant digits.

In my humble opinion, the problem is not as simple as it seems. We might want to consider the more general problem of displaying numbers, that is, the number of significant digits but also the number format. We could draw inspiration from the calculators' display, such as HP and other calculators, in scientific notation and engineering notation.

The javascript function toPrecision(), or a similar function, can only be a one-size-fits-all solution which has some gaps. I think that if we wanted to do the right thing for the Formulas question, we would have to develop a complete scientific display system and make sure it is the best.