<< Chapter < Page Chapter >> Page >

It is up to you, the author of the script, to determine what that length should be and to provide that information as a parameter to the toPrecision method.

Combined operations

This is where things become a little hazy. I have been unable to find definitive information as to how to treat the precision and the number ofsignificant figures when doing computations that combine addition and/or subtraction with multiplication and/or division.

Two contradictory procedures

I have found two procedures documented on the web that seem to be somewhat contradictory. Both sources seem to say that you should perform the additionand/or subtraction first and that you should apply rule #1 to the results. However, they differ with regard to how stringently you apply that rulebefore moving on to the multiplication and/or division.

The more stringent procedure

One source seems to suggest that you should round the results of the addition and/or subtraction according to rule #1 and replace the addition or subtraction expression in your overall expressionwith the rounded result. Using that approach, you simply create one the factors that will be used later in the multiplication and/or division. That factor has awell-defined number of significant figures.

Then you proceed with the multiplication and/or division and adjust the number of significant figures in the final result according to rule #2 .

The less stringent procedure

The other source seems to suggest that you mentally round the results of the addition and/or subtraction according to rule #1 and make a note of the number of significant figures that would result if you wereto actually round the result. However, you should not actually round the result at that point in time. In other words, you should use the raw result of the addition and/or subtraction as a factor in theupcoming multiplication and/or division knowing that you may be carrying excess precision according to rule #1 .

Then you proceed with the multiplication and/or division and adjust the number of significant figures in the final result according to rule #2 . However, when you adjust the number of significant figures, you should include the number of significant figures fromyour note in the decision process. If that is the smallest number of significant figures of all the factors, you should use it as the number of significant figures forthe final result.

Consult with your instructor

Before accepting either of these procedures as the correct procedure, I recommend that you consult with your physics instructor to confirm which, ifeither of the procedures is correct for combined operations.

An exercise involving combined operations

Evaluate the following expression and display the final result with the correct number of significant figures.

(169.01 + 3294.6372) * (0.00365 - 29.333)

Please copy the code from Listing 3 into an html file and open it in your browser.

Listing 3 . An exercise involving combined operations.
<!-- File JavaScript03.html --><html><body><script language="JavaScript1.3">//Compute, fix the number of decimal places, // and display the sum of two numbers.var a1 = 169.01 var a2 = 3294.6372var aSum = (a1 + a2).toFixed(2) document.write("aSum = " + aSum + "</br>") //Compute, fix the number of decimal places,// and display the difference between two // other numbers.var b1 = 0.00356 var b2 = 29.333var bDiff = (b1 - b2).toFixed(3) document.write("bDiff = " + bDiff + "</br>") //Compute and display the product of the// sum and the difference. var product = aSum * bDiffdocument.write("product = " + product + "</br>") //Round the product to the correct number// of significant figures based on the least // number of significant figures in the// factors. var final = product.toPrecision(5)document.write("final = " + final + "</br>") //Display a final line as a hedge against// unidentified coding errors. document.write("The End")</script></body></html>

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Accessible physics concepts for blind students. OpenStax CNX. Oct 02, 2015 Download for free at https://legacy.cnx.org/content/col11294/1.36
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Accessible physics concepts for blind students' conversation and receive update notifications?

Ask