What Is The Diffrence Between Math.floor And Math.round
Hi Guys,
Wat is the diffrence between these two?
I looked at the help, but i still dnt quite understand it!
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 09-26-2005, 11:24 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Math.floor? Round Down To Nearest 10th
Hi Folks, Math is not my friend so I need some help.
I want to round a whole number down to the nearest whole 10th.
Like 52, becomes 50. Or 49, becomes 40. Or 2005, becomes 2000.
Does that make sense? I imagine it has a math.floor approach, but I can not figure it out.
Thanks in advance for any help!!!
Controlling The Odds Of Math.floor(Math.random()
Hey,
Is there a way to set a random number in a array to showup maybe once a day. Or every 5000 views or loops, or something like that. I would love to be able to control the odds of a array. Cheers!
ActionScript Code:
var pic_array = new Array();
pic_array[0] = "images/1";
pic_array[1] = "images/2";
pic_array[2] = "images/3";
pic_array[3] = "images/4";
pic_array[4] = "images/5";
pic_array[5] = "images/6";
pic_array[6] = "images/7";
pic_array[7] = "images/8";
pic_array[8] = "images/9";
pic_array[9] = "images/10";
pic_array[10] = "images/11";
pic_array[11] = "images/12";
pic_array[12] = "images/13";
pic_array[13] = "images/14";
ranNum = Math.floor(Math.random()*pic_array.length);
holder_mc.loadMovie(pic_array[ranNum]+".jpg");
Math.ceil Ll Math.floor
Hi there,
I have code to dynamictween my mc's.Works great.I only need the if statement to work so when my square reaches it's new size and position I can load in my content using a holder.Can someone help me out on this if statement.
and instead off scaling the holder,etc I want to control it's xy position when hitting but0,...
but0.onRelease = function()
{
_root.square.dynTween({duration:6, _y:[350, "In", 60], _yscale:[200, "out", 5], callback:"_root.action1"});
if (Math.ceil(this._dynTween) == Math.ceil(_root.square) || Math.floor(this._dynTween) == Math.floor(_root.square)) {
if (_root.squareTrigger == 1) {
if (_root.squareLoaded == undefined)
_root.square.squareHolder.loadMovie("content0.swf" );
_root.square.squareHolder._xscale = 33;
_root.square.squareHolder._yscale = 33;
_root.square.squareHolder._x += 35;
_root.square.squareHolder._y += 35;
_root.squareLoaded = 1;
}
_root.square.squareHolder._visible = true;
_root.squareTrigger = 1;
}
}
}
Grtz,
Math.round(Math.random()*4)+1
Will this return values of 1 to 5 (inclusive).
If not, anyone know how to get random whole numbers 1 to 5?!
Cheers.
Dongle
Var I = Math.round(Math.random()*1)
this should return either 1 or 0?
but it seems to be returning something else as well and i dont know what it is???
function startXPos() {
var i = Math.round(Math.random()*1);
_root.test1 = i;
_root.test2 = t;
return i;
}
i have this just after
if (startXPos() == 0) {
startX = -500;
endX = 750;
} else if (startXPos() == 1) {
startX = 750;
endX = -500;
} else {
startX = 0;
endX = 0;
}
_root.test3 = startX;
_root.test4 = endX;
As far as i am aware this should never return 0 for these two values but it does?!?
can someone please tell what im doing wrong here?
Math.round And Just Plain Math
Hi, I'm back with another question.
I want my exam to show a percentage at the end. I guess I'll concatenate a 'percent sign' at the end, but right now I'm having trouble with the math.
There are 13 questions. This is what I have:
score = Math.round(right/13*100);
The scores are coming out all wrong. Any ideas would be greatly appreciated.
Dan
Math.round() Or Math.random()
Is it better to use Math.round() or Math.random() reason I am asking I think I read somehwere that one was better. My problem is that I have a number of movie clips that are attach dynamically. They move randomly on the stage but for some reason they just stop moving randomly.. I think there was a post somehwere about that but cannot seem to find it.
Math.floor?
Hi!
what is math.floor?
what do it do?
and, how shuld I use it?`
thanks
Albert
Math Floor
Hey al since the other game iv'e been trying to make was hard and no one knew Multiple hitTest,and iv'e been working on it or like a week or less//
I feel like i should make a cool City drager...
So if someOne can rust me up on this kinda code..
Mathfloor/
To drag a obkject then stop on the grid say size 30 and
maybe you guys can whip up a FLA..
Plz someone will help son i hope...
Ill be on my computer..l.........;,,,,l
Math.floor Loses 0
I have a captivate player that checks the time I run into the problem when I use the Math.floor to round the numbers it drops the 0 if for instance the time is 9:01, 9:1 is displayed. Another Example is 2:00 is displayed 2:0 It only does this if there is a 0 before the last number.
Here is part of my code
Code:
this.onLoad = function ()
{
capPath = _parent.target_mc;
m = Math.floor(capPath.rdinfoCurrentFrame/30/60);
s = MathDigits(Math.floor(capPath.rdinfoCurrentFrame/30%60));
tempo = m+":"+s+"/"+Math.floor(capPath.rdinfoFrameCount/30/60)+":"+Math.floor(capPath.rdinfoFrameCount/30%60);
}
[MX04] Math.floor Help
Hi! I have the below code to trace the current time in seconds. But I don't know why I can't use Math.floor to round up the "currenttime" digit...
But I could use Math.floor(12.123);
function updateTimer():Void {
currenttime = getTimer();
currenttime = currenttime /1000;
Math.floor(currenttime);
trace(currenttime+ "NEWTIME");
}
var intervalID:Number = setInterval(updateTimer, 1000);
Can anyone please help??
Thanks!!
[CS3] Help With The Math.floor Command
I have a project that has a calculation that come back with a number like 10.5. I need to round down a variable and get rid of the .5 using math.floor but i can't seem to figure out how to do it.
Thanks for the help
Global Math.floor()
Hi there is there a way to globally assign Math.floor() or Math.round() to a flash presentation, so that all values in the presentation are rounded off?
Weirdness In Math.floor
project width is 500
tile_width=25;
map_collumns=Stage.width/tile_width
trace(map_collumns)
Sometimes I get a decimal return. Then, when I close it,and run it again, it shows the correct answer.
Why is this?
Math Random And Floor
Hi all
Code:
rects[i].graphics.beginFill(Math.floor(Math.random( )*0xFFFFFF), 1);
I can't find , what floor and Math.random( ) do to this code.I have a reference .
Thanks advance .
Math.floor To Display Two Zeros
Anyone know of a way (or better way than I am doing it) to get Math.floor to display two numbers if the Math.floor integer is 0? Math.round seems to return only one zero also.
Currently I have a condidtional to check
Code:
myNum = Math.floor(myVar/1000);
if(myNum == 0){
myNum = "00";
}
Thanks,
Ivan
Math.floor, Variables.........fun Stuff
hey guys, if i'm trying to determine a destination frame for a button to refernce (gotoAndPlay) based on a percentage, would it be necessary for me to use Math.floor to make sure the result of the percentage is a whole number before trying to send the movie to the frame?
as some of you know, i've been working on upgrading a video player peice by piece for about a week now and i think i'm getting close to the end (finally). anyway, i'm currently working on a progress bar that is draggable to control the position of the movie. anyway, i've got all kinds of functions and variables that, to be honest, i dont really know anything about beyond what they're supposed to do based on what you guys have told me on here........anyway, one such example is an equation that calculates the appropriate frame for the movie based on where the user releases the progress bar handle (i.e. _x of the handle/160; 160 being the max _x for the handle, then multiply that result by the total frames of the movie). i ran a trace, and that part seems to output correctly, but in MOST cases it outputs something like 506.134882..........(random example).
anyway, what i was thinking is that maybe i need to round that number to the nearest whole number because there's no such frame as xxx.134. does that make sense?
if that IS the case, is it legal for me to simply add that into the AS phrase that tells the movie to go to that frame, or does it have to be included into the equation itself?
here's the two lines in question:
ActionScript Code:
var vidPercentTwo:Number = (_root.sliderMC.handleMC._x/160)*_root.tutVideo._totalframes;
_root.tutVideo.gotoAndStop(Math.floor(vidPercentTwo));
these are both included into the function for the release of the button.......basically i guess i need to know if i'm on the right track w/ the Math.floor business and can i actually include the variable name in the Math.floor() as i did in the example above, or will that give me problems??
i'm off work now, so i'll be offline till tomorrow morning, i'll check up on what you guys think then...thanks so much!!
-james
Easy(?) Question About Math.floor(x);
I get undefined when I try this code:
x=12.5
trace(math.floor(x));
Are expressions allowed in the operator? or what am I doing wrong?
Thank you very very much!
Math.floor Simple Question
Hi Again-
For some reason my math.floor function is not working (trace yields "undefined")... Im sure its something simple, but Im not seeing it. Suggestions??? Thanks!!!
ActionScript Code:
thumbNum = 26;total = thumbNum * 200;wholeSteps = math.floor(total/600);trace (wholeSteps);
Math.floor/ceil Not Working?
OK... I cannot get "this.dx" to either round down OR up? It keeps tracing out as decimal.
Code:
if (this._x>(rightwall-(this._width/2))) {
this._x = rightwall-this._width/2;
this.dx *= -.9;
Math.ceil(this.dx);
trace(this.dx);
rotateDir = "left";
}
// hit the left wall
if (this._x<(leftwall+(this._width/2))) {
this._x = leftwall+this._width/2;
this.dx *= -.9;
Math.floor(this.dx);
trace(this.dx);
rotateDir = "right";
}
anyone know what gives????
Cheers!
What Keeps My Movie From Stopping Properly? Math.floor/interval
Hey all,
this is driving me nuts.
I have a movie, in it lies a button with which I jump to another position in the _root timeline.
At that position is a stop(); command.
The movie just wont stop while this is running in another mc1 deeper in the file
:
Code:
stop();
onEnterFrame = function() {
c=Math.floor(Math.random() * (1500 - 0)) + 150;
var Interval1 = setInterval(function () {
b=Math.floor(Math.random() * (7 - 0)) + 1;
gotoAndPlay(b);
clearInterval(Interval1);
}, c);
}
What this does in the mc1 is basically creating a random number between 150 and 1500 and a random number between 0 and 7, then jumping to a random frame (numbered from 1-7) after waiting for a random time (150-1500ms).
My _root stops properly when I remove the code posted above.
Why is this happening and how can I have a mc1 in my movie which waits for a random time and then jumps to a random frame, while I want to move around in my _root timeline?
I should add, the mcs1 which wait and move to a random frame are non existent on the position I want to move to in _root.
Could that be part of the problem?
Do I have to somehow remove the wait and choose random frame to jump to function in mc1, when moving around in _root?
How would i do this?
Any help is greatly appreciated,
dual
AS2 - How To Center Flash On Page Load In Browser (using Math.floor() For Pixel Alignment)?
Last edited by gadz : 2008-10-20 at 04:41.
I need help. I have a swf that has a tiled bmp background, a movieclip (main) with all the content (except the loader movieclip) that is automatically centered on the stage at browser resize (using Math.floor() for pixel alignment). The SWF is 100% high and wide so it fills the browser, I'm using FlashScaler to show scrollbars in the browser when needed.
My problem is that when the swf loads in the browser, the loader movieclip and the main movieclip do not center on the stage of the swf until the browser window is resized manually.
On the timeline I have an actions layer with the following code:
PHP Code:
stop();
import flash.display.BitmapData;
import flash.external.ExternalInterface;
var sw:Number = System.capabilities.screenResolutionX;
var sh:Number = System.capabilities.screenResolutionY;
var tile:BitmapData = BitmapData.loadBitmap("tile");
function fillBG():Void {
this.beginBitmapFill(tile);
this.moveTo(0,0);
this.lineTo(sw,0);
this.lineTo(sw,sh);
this.lineTo(0,sh);
this.lineTo(0,0);
this.endFill();
};
fillBG();
Stage.align = "TL";
Stage.scaleMode = "noscale";
Stage.addListener({onResize:reposition});
function reposition() {
fillBG();
var mc = _root.main;
var newX = Math.floor(Stage.width / 2);
mc._x = newX;
};
reposition();
Below it I have another layer with a preloader that uses the following code:
PHP Code:
onClipEvent (load) {
total = _root.getBytesTotal();
}
onClipEvent (enterFrame) {
loaded = _root.getBytesLoaded();
percent = int(loaded/total*100);
text = percent+"%";
gotoAndStop(percent);
if (loaded == total) {
_root.gotoAndPlay(2);
}
}
And below the preloader layer, I have the content movie clip (main) layer that starts on frame(2) after the preloader is finished loading the swf.
The HTML code is the following:
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Crosswind Group</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="StyleSheet" href="style/main.css" type="text/css" media="screen,print" />
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/flashscaler.js"></script>
<script type="text/javascript">
var flashvars = {};
var params = { scale: "noScale" };
var attributes = {};
swfobject.embedSWF("main.swf", "flashmovie", "100%", "100%", "8", false,
flashvars, params, attributes);
</script>
</head>
<body>
<div id="flashcontent">
<div id="flashmovie">
<h2>SORRY!</h2>
<p>We have detected that you do not have the Flash Player plugin
required to view this website.</p>
<p>Download the latest <a href="http://www.adobe.com/shockwave/download/
index.cgi?P1_Prod_Version=ShockwaveFlash">Flash Player</a> for free!
It takes just a few minutes to download and install.</p>
</div>
</div>
<script type="text/javascript">
scale = new FlashScaler("flashcontent",500,620);
</script>
</body>
</html>
And the css is:
PHP Code:
html {
height: 100%;
font-size: 100%;
overflow:auto;
}
body {
height: 100%;
margin: 0;
padding: 0;
background-color: #000;
color: #fff;
font-size: 76%;
font-family: "Courier New",Arial, Verdana, sans-serif;
}
a {
color: #666;
text-decoration: underline;
}
h2 {
margin-top: 2em;
}
#flashcontent {
overflow: hidden;
}
#noflash {
margin: 20px;
}
Here are the complete project files. (see attached zip file).
Attached Files
Math.round Or....?
Hi there,
This is a part of an as-script for a poll:
percent1 = Math.round(value1);
percent2 = Math.round(value2);
percent3 = Math.round(value3);
percent4 = Math.round(value4);
v1 = Math.round(value1) add "%";
v2 = Math.round(value2) add "%";
v3 = Math.round(value3) add "%";
v4 = Math.round(value4) add "%";
Now i want the sum of (v1+v2+v3+v4) to always equal 100. How do i accomplish that?
any suggestions?
D-Flyer
Math.round() HELP PLEASE
Right guys if you have a look @ the loink you will see what iam talking about. For some reason the window won't go to targetx and targety plus it woin't round down either.
www.innovativedesigns.org.uk/untitled.htm
_y += Math.round(vf-_y)/5;
I tried the Math.round too, but… the text keeps blurring....
(I already read all the threads about “blurred scrolling pixel fonts” to check if my question was already made and answered)
I have this movie with Y sliding and X sliding which is having an specific blurring problem when sliding backwards in the case of Y sliding and when sliding forwards in the case of X sliding.
All the text boxes and the movies that contain them are set up to integer coordinates. It seems as there is something with the code that is placing the slider in a non-integer coordinate after clicking…. Any ideas? Thank you very much.
PS: I’m referring mostly to the text when stops since while sliding the blur is visible in any direction. It would be great if I can solve that too but by now I would be happy to solve just the text when stops.
The code (written in “base” mc) for the Y Slider is:
onClipEvent (load) {
vf = 314;
}
onClipEvent (enterFrame) {
_y += (vf-_y)/5;
}
each button has this code to move the slider (in which “base” is the instance name of the movie that contains the text and loads the pics)
first button:
on (press) {
base.vf = 314;
}
second button:
on (press) {
base.vf = 38;
}
And so on…
The code (written on “base” mc) for the Y Slider (located inside “base”) is:
onClipEvent (load) {
vf = 0;
}
onClipEvent (enterFrame) {
_x += (vf-_x)/5;
}
each button has this code:
first button:
on (press) {
base2003.vf = 0;
}
second button:
on (press) {
base2003.vf = -180;
}
And so on…
Math.round()
is it possible to do a Math.round that doesn't round to the nearest whole number, but to the nearest half number?
Ex:
Math.round(5.6)=5.5
NOT
Math.round(5.6)=6
Thanks
Math.round()
is it possible to do a Math.round that doesn't round to the nearest whole number, but to the nearest half number?
Ex:
Math.round(5.6)=5.5
NOT
Math.round(5.6)=6
Thanks
Using Math.round
Hello all,
I amm trying to use math. round so that the following piece of code will reposotion it's target object on an integer rather than a fraction. Can anyone tell me how to add that to this code?
Thanks much!
SumSum
// Keeps the MENU in place when the movie is resized.
menuMC.onResize = function () {
this._x = (Stage.width/2)-390;
this._y = (Stage.height/2)-185;
}
// Register titleClip to be notified when movie is resized.
Stage.addListener(menuMC);
// Set initial position of title clip.
this.menuMC.onResize();
Math.round 0.25 0.5 0.75
Hi,
I am trying to round of a number so that it displays as 1, 1.25, 1.5, 1.75, 2 etc
I have it rounding off to 2 decimal places with:
temp = Math.round(temp * 100) / 100;
but thats not quite what I want,
Any idea? Thanks,
Math.round
Gday,
Im having a hard time getting my head around this, and I feel stupid for posting this, but any help would be good
using Flash 8,
want to round a number to the nearest 40, here is the macromedia live doc syntax
public static round(x:Number) : Number
This is my first attemp to learn actionscript 2.0. so what is
public static?,
And how do I use this?
Cheers, James
Math.round - Flv ?
I have been using the following code for playing flv's however I always run into a problem when the actual obj.duration is close to a half increment. Example, the actual video length is 15.53 seconds.
So the Math.round(_global.videoDuration); will round up to 16, where as the Math.round(ns.time); at the end of the video shows 0. This means that my IF statement never fires.
My solution to this problem has always been to go back into the video file and add a little bit of black video so that it doesn't end up on a half increment.
Now here is my question, is there a better way to set up the onEnterFrame function so that I don't have to adjust the video file?
ActionScript Code:
_root.stop();
var netConn = new NetConnection();
netConn.connect(null);
var ns = new NetStream(netConn);
my_video.attachVideo(ns);
ns.setBufferTime(5);
ns.play("videos/Final Surgical OptionCD.flv");
//
getTotalTime = function () {
ns.onMetaData = function(obj) {
_global.videoDuration = obj.duration;
trace(obj.duration);
};
};
// monitors the current position of the playhead against the total playing time
onEnterFrame = function () {
getTotalTime();
totalPlayingTime = Math.round(_global.videoDuration);
currentPlayingTime = Math.round(ns.time); //;
trace("currentPlayingTime "+currentPlayingTime)
trace("totalPlayingTime "+totalPlayingTime)
if (totalPlayingTime == currentPlayingTime) {
//ns.seek(0);
// ns.pause();
ns.close();
// ns.play()
//gotoAndPlay("start");
}
};
Math.Round
Hi all ,
I am using a script of..
letitbe = (Math.round (num))
this round 's off to the nearest whole number , How can I round off to the nearest 100?
Thanks in advance.
Edited: 11/27/2007 at 11:09:44 AM by Balloony2
Math.round Help
Hi,
I have a nuber= 0.00999999995 and i need to round it to 0.01.
I mean round the numbers but with 2 digits of presition.
any ideas?
tks
Math.round
Hey, can you set the precision at which Math.round works? thanks.
Math.round()
Hi
I have a problem facing might seems very small but just couldnt do it.
I want to roundup a value up to one decimal only. For example,
x=100.238294;
trace(Math.round(x*10)/10)
this works fine but if the number is : 100.0000000000
then I want my output to be 100.0. But its showing 100 only. Does anyone knows how to get this done or any other way to do it. Please let me know .Thanx
Ashish
Math.Round()?
What is math.round() do? In kirupa's Random numbers tutorial, he explained the use of math.floor(), but said round() was for another time. Yet I see that, and not .floor() in use in the random movement tutorial.
What is it? What does it do?
Math.round()
quick question
how do you round a number to 4 digits...
so 3.45356345345
is 3.456
and 1
is 1.000
//VoS
Math.round
How to round the figures for percentage loaded?
onEnterFrame = function () {
var percent_loaded = _root.getBytesLoaded()/_root.getBytesTotal();
preloader_mc.value = percent_loaded;
_root.info.text = percent_loaded * 100;
if (percent_loaded == 1) {
delete onEnterFrame;
gotoAndStop(2);
}
};
[help] Using Math.round()?
I'm not sure how to use the Math.round() function in Flash?
Im trying to take a value from a dynamic textbox on the stage and round that number off to a whole number.
I would really appreciate some help!
Math.round
Hey, can you set the precision at which Math.round works? thanks.
Math.round()
Hi
I have a problem facing might seems very small but just couldnt do it.
I want to roundup a value up to one decimal only. For example,
x=100.238294;
trace(Math.round(x*10)/10)
this works fine but if the number is : 100.0000000000
then I want my output to be 100.0. But its showing 100 only. Does anyone knows how to get this done or any other way to do it. Please let me know .Thanx
Ashish
Math.Round()?
What is math.round() do? In kirupa's Random numbers tutorial, he explained the use of math.floor(), but said round() was for another time. Yet I see that, and not .floor() in use in the random movement tutorial.
What is it? What does it do?
Math.round()
quick question
how do you round a number to 4 digits...
so 3.45356345345
is 3.456
and 1
is 1.000
//VoS
Math.round() HELP PLEASE
Right guys if you have a look @ the loink you will see what iam talking
about. For some reason the window won't go to targetx and targety plus it
won't round down either.
www.innovativedesigns.org.uk/untitled.htm
Math.round(); Question
hello,
is it possible to round a floating point number to a certain
value?
what i mean is:
i want to round 1.85038723 to 1.8504
(skip the last 4 numbers).
is there a possibility?
thx
Math.round Not Working
I'm making one of those image viewers where the frame resizes to fit the image. I'm still quite far off finishing but I've hit a problem already.
I can't get the frame width and height to exactly equal the img width and height. It's always .05 out or something, even though I'm using Math.round!!
I've attached the movie and the text file from where the image details are stored.
In the bottom left of the movie have 4 vars which you can watch as it resizes. first2 top and bottom are the width and the height of the frame. The next two top and bottom are the number it increases or decreases the frame by.
If the equation works these text boxes disappear because it moves to the next frame (where it would show the image when I get that far.)
The 2 buttons in the right corner are to swap between the 2 pretend images.
Hope someone can help me. It's an MX file but can send a flash5 on request.
I don't want the whole thing done for me....just pointers on what I'm doin wrong.
Cheers
Math.round Question
Hi
Can anyone tell me why the following use of
Math.round(Math.random())does not work and suggest how I can get it to work, please.
myQuote=new Array(new Array(”one”, “two”, “three”), new Array(“four”, “five”,“six”));
myQuote=Math.round(Math.random()*(myQuote.length)) ;
Thanks in advance.
John
jdshipton@rogers.com
Math.round Function
i'm just messing arround with it but i can't get this thing to work.
if i have some script like
_level0.number=random(51);
how can i then round this number to the nearest 5?
I don't just want to use _level0.number=random(11)*5
cos then i find out how to use round
so far i have something like math.round(level0.number)50; but i can't really remember
plz help if u can (i'm using flash 5)
==================
TiMo
Math.round Question
I want to round a number to the nearest .5 (example: 12.0, 13.5, etc.). The round method only rounds to the nearest integer. Any ideas?
Thanks.
|