<< Chapter < Page | Chapter >> Page > |
Examples of significant digits
Referring back to the physics textbook mentioned earlier, Figure 1 shows:
Figure 1 . Examples of significant figures. |
---|
1. 409.8 4 4.098e+2
2. 0.058700 5 5.87e-23. 9500 ambiguous 9.5e+3
4. 950.0 * 10^1 4 9.5e+3 |
Note that the default JavaScript exponential representation fails to display the significant trailing zeros for the numbers on row 2 and row 5. Iwill show you some ways that you may be able to deal with this issue later but you may not find them to be very straightforward.
Beyond knowing about scientific notation and significant figures from a formatting viewpoint, you need to know how to perform arithmetic whilesatisfying the rules for scientific notation and significant figures.
Performing arithmetic involves three main rules :
An exercise involving addition
Please copy the JavaScript code shown in Listing 1 into an html file and open the file in your browser.
Listing 1 . An exercise involving addition. |
---|
<!-- File JavaScript01.html --><html><body><script language="JavaScript1.3">//Compute and display the sum of three
// numbersvar a = 169.01
var b = 0.00356var c = 385.293
var sum = a + b + cdocument.write("sum = " + sum + "<br/>")
//Round the sum to the correct number// of digits to the right of the decimal
// point.var round = sum.toFixed(2)
document.write("round = " + round + "<br/>")
//Display a final line as a hedge against// unidentified coding errors.
document.write("The End")</script></body></html> |
Screen output
When you open the html file in your browser, the text shown in Figure 2 should appear in your browser.
Figure 2 . Screen output from Listing #1. |
---|
sum = 554.30656
round = 554.31The End |
The code in Listing 1 begins by declaring three variables named a , b , and c , adding them together, and displaying the sum in the JavaScript default format in the browser window.
Too many decimal digits
As you can see from the first line in Figure 2 , the result is computed and displayed with eight decimal digits, five of which are to the right of thedecimal point. We know, however, from rule #1 , that we should present the result rounded to a precision of two digits to theright of the decimal point in order to match the least precise of the numbers included in the sum. In this case, the value stored in the variable named a is the least precise.
Notification Switch
Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?