-
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?
Life is what you make it!
-
ʞ33ƃ
you could do
code:
mynum=1.899999999999999999999
mynum=math.floor(mynum*10)/10
-
SaphuA
Originally posted by xMCNUGGETx
you could do
code:
mynum=1.899999999999999999999
mynum=math.floor(mynum*10)/10
I would choose Math.round
code:
var badNum = 1.899999999999999999999
var goodNum = Math.round(badNum*10)/10
-
Heli Attack!
Why? Round would bring errors when the numbers have fractions greater than .5 in them. Floor is the correct way to do this.
-
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
-
Senior Member
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
-
-
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.
-
Heli Attack!
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.
-
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") {
var badNum = 0.1;
var goodNum = Math.log(badNum*10)/10;
milage += goodNum;
}
if anyone can help it'll be great.
Life is what you make it!
-
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?
-
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.badNum=0.1;
_root.tach.goodNum=Math.int(_root.tach.badNum*10)/10;
_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
-
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
-
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.
-
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).
-
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.
See also
Math.floor
-
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
-
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.
-
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
-
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.
Life is what you make it!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|