all groups > flash actionscript > december 2005 >
You're in the

flash actionscript

group:

math round


math round Brian
12/26/2005 9:35:24 PM
flash actionscript:
I would like to use the math round method, but am having some problems
with it. I have the following, and that goes into a text field to show
load progress:

var numPercentLoaded:Number = numBytesLoaded / numBytesTotal * 100;
numberLoaded_mc.numberBox = numPercentLoaded;

The problem is that the number has a bunch of decimal points that I
don't really want there. So I thought I could do something like this,
but that does seem to be wrong.

var numPercentLoaded:Number = numBytesLoaded / numBytesTotal * 100;
Math.round(numPercentLoaded);
numberLoaded_mc.numberBox = numPercentLoaded;

So I would like to round off the numPercentLoaded varible. What am I
doing wrong?

Thanks for any help!
Brian
Re: math round David Stiller
12/27/2005 1:29:13 AM
Brian,

[quoted text, click to view]

Ah, yup. I've done that, too. The problem here is that you're not
updating the value of your variable, you're simply invoking Math.round().
The Math.round() method returns a number, and you're not using that number.
This would work ...

var numPercentLoaded:Number = numBytesLoaded / numBytesTotal * 100;
numPercentLoaded = Math.round(numPercentLoaded);
numberLoaded_mc.numberBox = numPercentLoaded;

-- though, numberBox is the text field, right? So change that last line
from what it is to this:

numberLoaded_mc.numberBox.text = numPercentLoaded;

(you're updating the text property of the text field with the instance name
numberBox, I presume). Or, if you wanted to express the above three lines
more succinctly:

var numPercentLoaded:Number = numBytesLoaded / numBytesTotal * 100;
numberLoaded_mc.numberBox.text = Math.round(numPercentLoaded);


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Re: math round kglad
12/27/2005 6:32:45 AM
var numPercentLoaded:Number = numBytesLoaded / numBytesTotal * 100;
Re: math round Brian
12/27/2005 7:12:21 AM
Re: math round kglad
12/27/2005 3:44:17 PM
AddThis Social Bookmark Button