# quick question on how to setprecision in flash

• 05-19-2004, 09:52 PM
hmoob-ky
quick question on how to setprecision in flash
hey, can anyone show me how to setprecision in flash mx 2004?

This is what I want to do:
I want to show the mileage of a car climb as you progress... but the only problem is that it shows the decimals too, and all I want it to do is show the decimals to the tenth place, but it keeps jumping and showing it to the thousandths and so forth.

example: I want the text to display like this 1.8 and not like this 1.899999999999999999999

I know that setprecision is C++ but can it be done in Flash? can anyone help?
• 05-19-2004, 10:03 PM
xMCNUGGETx
you could do
code:
```
mynum=1.899999999999999999999
mynum=math.floor(mynum*10)/10
```

• 05-20-2004, 04:22 AM
SaphuA
Quote:

Originally posted by xMCNUGGETx
you could do
code:
```
mynum=1.899999999999999999999
mynum=math.floor(mynum*10)/10
```

I would choose Math.round ;)

code:
```
```

• 05-20-2004, 05:47 AM
iopred
Why? Round would bring errors when the numbers have fractions greater than .5 in them. Floor is the correct way to do this.
• 05-20-2004, 06:06 AM
SaphuA
Offcourse not...

Here are some samples:
Code:

```45.216 Start nr. 452.16 *10 452    Math.round 45.2  /10 93.688 Start nr. 936.88 *10 937    Math.round 93.7  /10```
• 05-20-2004, 06:28 AM
TeroLebe
no no SaphuA....
iopred is right in this one.
hmoob-ky said:
example: I want the text to display like this 1.8 and not like this 1.899999999999999999999

example
Math.round(1.89*10)/10 --> 1.9
Math.ceil(1.89*10)/10 --> 1.9
Math.floor(1.89*10)/10 --> 1.8 THIS LOOKS RIGHT!
int(1.89*10)/10 --> 1.8 so does this

and negative ones
Math.round(-1.89*10)/10 --> -1.9
Math.ceil(-1.89*10)/10 --> -1.8
Math.floor(-1.89*10)/10 --> -1.9
int(-1.89*10)/10 --> -1.8
• 05-20-2004, 06:30 AM
jonmack
I don't think you quite understand, Saph. ;)

Round ( and floor and ceil ) give an integer number. Hmoob-ky wants to have decimal precision, but only outputted to a certain number number of decimal points. A decimal point isn't an error. :)

EDIT:
Hmm, okies, maybe me no understand anyfink ok? :D Previous poster beat me to it and with a better answer. Examples... why didn't I think of that. Oh well. I really shouldn't post straight after an exam only having 4 hours sleep... bleh.
• 05-20-2004, 06:57 AM
SaphuA
Oh wait...

But then the name of the threat is wrong, using the Math.floor function is less precise then using Math.round!

What hmoob-ky wants is to chop of all decimals, except the first one. Didn't catch that, sorry.
• 05-20-2004, 07:49 AM
iopred
setPrecision is a function in C++ which changes the way all double/floats are displayed when sent to the output stream (eg. the screen), saying how many numbers are used to display the number, it doesnt round off the end, merely displaying a specified number of decimal points.
• 05-20-2004, 03:44 PM
hmoob-ky
thanks for the help guys....

Math.floor worked for a while, until it got to 6, then it started to display 6.199999999999 until it got to 9.19999999999, then after that it went back to showing 10.1

here is the coding that I used:

tellTarget ("_root.tach") {
milage += goodNum;
}

if anyone can help it'll be great.
• 05-20-2004, 03:51 PM
SaphuA
:)
Hey,
Could you explain what's wrong? The code the guys posted works how it should do. Isn't there someone else wrong in your code?

PS: Shouldn't you stop using Flash 4 syntax? ;)
• 05-20-2004, 04:18 PM
Ihoss
as aphua said, dont use tellTarget :)

im not sure why your using log though. log is the logarithm of a number, ie how many times does 2 have to be mulitplied with itself to get 8?

if milage is wrong, then round it too. this is the code that i would use:
code:
```
_root.tach.milage+=_root.tach.goodNum;
_root.tach.milage=Math.int(_root.tach.milage*10)/10;
```

I see that you have 2k4 and int might not work, so use floor instead :)
• 05-20-2004, 04:42 PM
jtnw
Ihoss, It's not Math.int(), but simply 'int()'.

Also, I'd recommend using 'int()' since 'Math.floor()' will give incorrect results with negative numbers.
ie:
code:
```trace(int(-5.23456*10)/10);//-5.2
trace(Math.floor(-5.23456*10)/10);//-5.3```

jtnw
• 05-20-2004, 04:45 PM
Ihoss
thanks for the correction jtnw (i cant believe how a name with 4 letters can take so long to pronounce). but int is depriciated in flash mx so i wasnt sure if it was in 2k4.
• 05-20-2004, 05:08 PM
jtnw
I don't think int is depriciated because as far as I know, there isn't anything that replaces it. int returns the integral part of a number, in other words, everything to the left of the decimal point (This is actually called truncating). Math.floor, however, returns the integer that is closest to negative infinity.

jtnw

PS, ya, my name does get annoying to pronounce, but for some reason, I've come to pronounce it as jit-new (don't ask).
• 05-20-2004, 05:12 PM
Ihoss
i searched for int in the function list in flash and i got this:
int

Availability

Flash Player 4. This function has been deprecated in Flash 5 in favor of the Math.round method.

Usage

int(value)

Parameters

value A number to be rounded to an integer.

Returns

Nothing.

Description

Function; converts a decimal number to the closest integer value.

Math.floor
• 05-20-2004, 05:25 PM
jtnw
That's kind of odd, since Math.round does something completely different.

Oh well, I'm still in favor of using the fastest solution, even if it's Flash 4 script. Since int is faster, I use it because I don't see a reason not to.

Each to his own,

jtnw
• 05-20-2004, 05:42 PM
Ihoss
i agree. I use random(56); too, as its a lot faster than Math.floor(Math.random()*56);. I dont see why MM takes away these functions, as their quite useful.
• 05-20-2004, 05:47 PM
jtnw
MM doesn't actually take the functions away, they just strongly advise against them. I'm sure int will still work in Flash Player 26, maybe not just in the IDE.

jtnw
• 05-20-2004, 06:22 PM
hmoob-ky
oops, my bad... i had that log there because i started experiment with it... Thanks for the input guys. I finally got it working the way I wanted to.