Decimal Places
A Flash Developer Resource Site

1. I am doing a simple flash exercise for my job which involves learning about "significant figures" in Maths.For the first box I want the user to input a number which always has a range of 2 decimal places minimum. Then the user chooses how many decimal places the end result is. For example entering 2.759, a user then puts a random number, lets say 2 decimal places and the final result is 2.76. Is there any way of doing this as I am struggling to compose one with the Maths functions available.

Matt

2. If I understood you right (I'm German so sometimes it's a bit tricky to understand all the Mathematical terms in English
You need to bring every number you don't want to be rounded before the point so let's say you have 2.759 and want 2.76:

Math.round(2.759*100)/100 = 2.76

if you want it to be one number behind the point:

Math.round(2.759*10)/10 = 2.8

Just choose some 10^x according to how many decimal places you like... got the idea?

3. ## significant figures

are tricky to program.

because 1.5 has two significant figures
1.5000 has 5sf
.00000015 has 2sf
1.0000005 has 8sf
500 has only one! that's a tricky one
50. has two! ugh.

try telling a program that, it can be a pain.
it boils down to

Trailing zeros do, as long as they are followed by a decimal point, or they follow the decimal point
Middle zeros do

you have to capture the number as a string, evaluate it's value and store that, then crop any leading zeros and count the length of the remaining string without the decimal.

Why do we need sig figs?
the idea is that if you know it's 3383.52 miles to where you are going, and you set you cruise control for 55 mph, how long does it take you to get there?

If you said 61.51854545 hours, you are pretending to know more about the situation than you do, that is, do you really know you arrival time to within a fraction of a second?

So how confident are you? Well, the number in you data with the fewest sfs is 55, which has 2.

Are you ready for the really odd bit? What if it's a round trip? When you multiply by 2 to get the answer, doesn't 2 just have 1sf?! so do you lose data? No you don't, actually. In this case 2 is not data, it's a pure number, and it's assumed to be 2.000000000000000000000000, or however many trailing zeros are needed to match the precision of the data.

4. ## Re: significant figures

Originally posted by ironmallet
you have to capture the number as a string, evaluate it's value and store that, then crop any leading zeros and count the length of the remaining string without the decimal.
How might you do that.

I'm creating a program right now where this would come in handy. Sometimes the output is of the magnitude 10^-8 and sometimes it's 10^-4. Right now I'm using the Math.round(value*100000000000)/100000000000 to make sure I get a few sig figs if it is 10^-8.

If that was confusing, this is what I mean.

Depending out the numbers input into the equation, the output can be:

1.915e-8
or
1.5424254e-4

Is there a way to make the output:

1.915e-8
or
1.542e-4

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap