Ah, sig figs. I remember doing these last year in Chemistry and WOW, were they difficult to get down. Took me nearly half the school year to finally get a hang on them, and that was after tons of points were ticked off because of one too many zeros.
I'm pretty sure it's possible to do this. First things first, we gotta know the rules, right? The first set, from usca.edu…
1) ALL non-__**zero**__ numbers (1,2,3,4,5,6,7,8,9) are ALWAYS significant.
2) ALL __**zeros**__ between non-zero numbers are ALWAYS significant.
3) ALL __**zeroes**__ which are SIMULTANEOUSLY to the right of the decimal point AND at the end of the number are ALWAYS significant.
4) ALL __**zeroes**__ which are to the left of a written decimal point and are in a number >= 10 are ALWAYS significant.
What do all these have in common? If you store your answer to a string, you can use inString(string, search-string) to find the zeros, followed by sub(string, start, length) to cut off the non-significant digits.
The next set of rules involve addition, subtraction, multiplication, and division. Luckily, these are a heck of a lot easier.
Addition and Subtraction:
When adding or subtracting numbers, count the NUMBER OF DECIMAL PLACES to determine the number of significant figures. The answer cannot CONTAIN
MORE PLACES AFTER THE DECIMAL POINT THAN THE SMALLEST NUMBER OF DECIMAL PLACES in the numbers being added or subtracted.
Multiplication and Division:
When multiplying or dividing numbers, count the NUMBER OF SIGNIFICANT FIGURES. The answer cannot CONTAIN MORE SIGNIFICANT FIGURES THAN
THE NUMBER BEING MULTIPLIED OR DIVIDED with the LEAST NUMBER OF SIGNIFICANT FIGURES.
Use length(string) to count the figures of each variable you are counting, then use sub( again to cut off the extra digits. Don't forget to use expr(string) to evaluate your string if you input your calculations directly into your program.
Hope that helped!