...

View Full Version : Javascript Calculator Significant Figures



tark_theshark
12-01-2006, 01:39 PM
Basically, i'm in 11th grade and i just got an assignment where im supposed to display 5 prompts, have the user type in numbers, the numbers multiply, and then these numbers are to be displayed in signifcant figures.

The first part is cake. The numbers multiply and everything, and I discovered a function called [var].toPrecision() which gives me significant figures according to the number I ask manually.

Unfortunatly the assignment is much more technically than that. If for example i multiply 1.2222222 * 100 the signifcant figures should end at the lowest decimal, making the answer 122. And if i multiply 33.33 * 33.33 then the lowest decimal is to the hundreths place and the answer is 99.99.

Can someone please help me with this?? I know very little about javascript and it is the first language i have learned. Is there a master out there who can offer an approach to this to a newbie?

nikkiH
12-01-2006, 04:07 PM
There is already a javascript built-in for setting a number to a certain amount of decimal places.

toFixed()

Other than that, I'm not sure what you're asking. Can you be a little more clear on the assignment?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum