Rounding Numbers
How do I round a number like this: 23.55 to become 23.6?
Math.round is too general. Do I need to split the value up and do text-type formatting on it?
Thanks
FlashKit > Flash Help > Flash ActionScript
Posted on: 03-08-2002, 06:53 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Rounding Numbers
Currently I have this actionscript code:
Code:
if (_root.PeriodsInNet1 != 00) {
_root.GoalsAgainstAvg1 = Number(_root.GoalsAgainst1)/Number(_root.PeriodsInNet1);
Most of the time it will be a result such as 0.343 I want it to show up as .343 instead.
Rounding Numbers
Whats the best way to round of a numeber contained in a variable from like... 5.34234356543 to just 2 decimals..?
Rounding Numbers
I'm sure there's an obvious and simple script for this, but can anyone tell me how to make a script to round numbers to the nearest whole number?
oh yeah, the only decimals will be .5, such as 4.5, 7.5, and such. Basically I'm deviding a user entered value by 2, and I want to be able to round the answer value up or down by .5
Rounding Down Numbers
I have a variable called "percentloaded" ive used a formulae to find the percent loaded. But it is about 20 digits long
I just want it to be two digits at most but I don't know how.
Can anyone help me im really struggling with this.
Thx
Rounding Numbers Up?
How do I get flash to round a number off to the higher integer.
for example in this Result should be 5
Result = Int(100/23);
thanks mark
Rounding Off Numbers
Hi there. I'm just wondering if there's a way you use get Flash to round of numbers so say the numbered returned to me was 16.0000004, then it would just display 16. Is that confusing? I'll try to give a better example.
Ok, I have a dynamic text box that displays the position of the _xmouse. but there are always those spots that come up like 14.95 or something, and it looks kinda bad, so if anyone could help me out here, I'd really appreciate it.
Rounding Numbers
say you are finding the average of two numeric variables, but wanted to return a whole number. how do you round that number?
Rounding Off Numbers
I have a small programme that works out how many shots someone fired and how many of them were hits and then gives the accuracy. This works fine and i get the accuracy, the only problem is i want the accuracy rounding off to the nearest integer. Any ideas how this is done would be very very welcome
Current code stands as this:
code:
on(release){
_global.hits=random(100);
_global.shots=random(100);
trace("clicked");
_root.shots.text="shots = "+_global.shots;
_root.hits.text="hits = "+_global.hits;
_root.accuracy.text="accuracy = "+_global.hits/_global.shots*100+"%";
}
Rounding Numbers...
Alright I know how to round a number, but ... I don't know what else to call this.
I get a number simular to 308,916.82 ... I don't have a problen doing th math to round that up ... Math.ceil ... my problem is making that number flat to the next position down like: 310,000. So if I had 1152 i'd want it to be 1200. If I had 4,500,345 I'd want 4,600,000. Make sense?
I hope so ... can anyone help me with this?
Rounding Numbers
How do I round numbers in action script, lets say I had 25.5 and I wanted to round it to 25. what would I do?
Rounding Off Numbers
Hi,
Can anyone help me with this:
I have this which outputs a quote as a number:
annualQuote_txt.text = "£"+annualTotal;
How can I round this number off?
Rounding Numbers
ok, when i use math.round to round a number up i.e. £4.345 i get £4.34, but i need 0.005 and over to round up and not 0.006? for money do i not? i always thought it was 0.005 and over to round up.
i.e. £4.345 = £4.34 rounded should be: £4.35
at the moment only rounds up with 0.006 and above.
Help With Rounding Numbers
Aii there..
okay I really need help with my code...okay how to put ".00" after round the numbers in 2 decimal places..this code works well with another numbers but if I'm try with this number it will output the numbers as "9" only...suppose to 9.00...ok here's the code
Code:
var basicsalary:Number;
basicsalary = 1877.61;
theresult = basicsalary*0.00479233226837061
trace(theresult);//output = 8.99813099041534
third_decimal_place = (int((theresult*1000))/1000 - int((theresult*100))/100) * 1000;
theresult = int((theresult*100))/100;
if (third_decimal_place >= 5){
theresult += 0.01;
}
trace(theresult); // it will output 9 suppose to 9.00
So how to alter the code so the result will be 9.00
hope someone will shed light for me...thnks in advanced
Rounding Numbers
I have an equation that needs to have an answer with two places after the decimal , i.e., 107.50 because I am dealing with money. The code I am using works as long as the last number isn't a zero. This is my code:
result=original*rate;
result=result*100;
result=Math.round (result);
result=result/100;
Right now I am getting:
133.56
107.5
Any ideas?
Rounding Numbers
dumb question:
im using get bytes total and getBytesLoaded; how do you round those to whole numbers?
thanks
Rounding Numbers For Preloader
I have a preloader that works and works well but is there any way of having it so that the percentage created by my current script can be rounded to the nearest % to avoid numbers like 54.749845984392837.
Thanks in Advance
Rounding Numbers In Flash
Im trying to round numbers that are shown are a speedometer for a racing game i am making im not sure wether to use the math.round feture to rmove all intergers making a whole number would that be the way to go?
Datagrid Rounding Numbers
Hello, I have a problem that I find seem to find the solution for.
I am playing around with Flex and am just inserting the returned xml from a php page into a datagrid. This is all fine.
The problem is one value group_id that is a number. When the datagrid takes it, it is rounding the number up. I don't know what is causing it or how to stop it. The group_id for example is 72157600298204491 but the datagrid is rounding it to 72157600298204500.
Here is all my code, its short
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" creationComplete="groupRequest.send()">
<mx:HTTPService id="groupRequest" url="getGroups.php" useProxy="false" method="POST"></mx:HTTPService>
<mx:HTTPService id="setRequest" url="getSet.php" useProxy="false" method="GET" resultFormat="xml" result="{photoResults.text = String(event.result)}">
<mx:request>
<id>{groups.selectedItem.group_id}</id>
</mx:request>
</mx:HTTPService>
<mx:DataGrid y="5" right="5" left="5" height="100" id="groups" dataProvider="{groupRequest.lastResult.groups.group}" click="setRequest.send()" >
<mx:columns>
<mx:DataGridColumn headerText="Photo Set" dataField="title" />
<mx:DataGridColumn headerText="Set ID" dataField="group_id"/>
<mx:DataGridColumn headerText="Date" dataField="date" width="150"/>
</mx:columns>
</mx:DataGrid>
<mx:TextArea right="5" left="5" bottom="5" top="115" id="photoResults" />
</mx:Application>
Any ideas?
Thanks
Rounding Numbers In A Variable Field?
I have a calculator like tool I am trying to create but would like to be able to round to certain decimal point.I have been given a function that is suppose to work but upon insertion to the file it prevents my calculator from working?????
here is the original scripts on the button
on (release) {
rev_c11 = 60/as_a7;
rev_c12 = 50/as_a7;
rev_c13 = 1.2/as_a7;
}
This works fine. I then put the script below on the first frame of the scene where the button resides...
trim(thenumber,place){
if (place>=0){
var temp= Math.pow(10,place);
return Math.round(thenumber*temp)/temp;
}
}
and reference the script like this off of the button...
on (release) {
rev_c11 = trim((60/as_a7),2);
rev_c12 = trim((50/as_a7),2);
rev_c13 = trim((1.2/as_a7),2);
My only problem is I can not get it to work, Anyone out there have another solution or see what I have done wrong???
please help, Thanks
nauhs
Rounding Numbers To 2 Decimal Places?
Hi all,
cam anyone remember how to calculate to 2 decimal places
ie
542.8688
to 2 decimal places would be
542.87
i can cut off the no required places but cant seem to round up or down accurately
any help greatfully appreciated
thanks in advance gilesb
Rounding Numbers *URGENT Help Needed*
I know you FLASHERS can help me, please read my post
My friends,
I come to you once again because I don't know how to fix a bug in a flash projector file (.EXE) that I'm working on.
My software:
It calculates the transport fee (value) for shipments (documents & products) based on its weight. Example: The user types the weight of the shipment into an input txt box and then I set up actions like:
=========================
if (weight<=0.5) {
value = "41.00";
} else if (weight<=1.0) {
value = "47.00";
} AND SO ON
=========================
Now I'll tell you where the bug is...
The price has non-constant increases every for every 0.5 kilo that you add to the total weight until it reaches 50 kilos.
So, after it reaches 50 kilos the price increases constantly and goes up U$ 2.60for every every 0.5 kilo added. I set up actions like the ones above (else if) from 0.5 to 50 kilos (lot of work).
For the shipments that are over 50 kilos I set up the action:
else if (weight>50) {
value = (((weight-50)*2)*2.60);
}
Translating: If weight is bigger than 50 kilos the price (value) will be ((weight - 50)*2)*2.60
===> example: weight = 60
60 - 50 = 10 kilos
10 * 2 = 20 (why 20???) The price increases every 0.5 kilo, doesn't it? So the correct price increasement would be 20 * 2.60
WHAT IF THE USER TYPES 50.5 (50 KILOGRAMS AND 500 GRAMS) ?????
Than my function won't work properly!!!!
Why??? Let's see: 50.5 - 50 = 0.05
I need to find a way to round the number up like this:
IF weight = 50.0000001 weight = 50.50
IF weight = anything bigger than 50 but smaller than 50.5 than round weight to 50.5
another example:
IF weight = 55.01 or 55.4 or 55.49 or 55.2 than weight = 55.5
WHY THIS???
Well...if weight gets rounded to 50.5:
50.5 - 50 = 0.5 than 0.5 * 2 = 1 *2.60 = add U$ 2.60 to the price!!
No matter what the weight is, if it's bigger than 50, it should be rounded to the next 1/2 a kilo (.50) for the function to work:
else if (weight>50) {
value = (((weight-50)*2)*2.60);
}
It starts at 50 (weight bigger than 50 and is supposed to work even if the typed weight is 100, 1000, 10.000 kilos....)
*** I need to round these weights because even if the spment is 50.1 kilos we charge 50.5 kilos. Always rounding up.***
We should only round the number up if it's bigger than 50, not equal to...
Did you understand my problem???? How can I help you to understand the BUG in order to help me????
I don't know what to do...
THANK YOU VERY MUCH!!!
Rounding Numbers And Adding Zeros...
Hi
Im kinda in a rush right now and haven't slept a lot in the last days. My brain's off now and I can't find the answer...
I need to put a counter which goes like that:
0.01
0.02
0.03, etc...
I rounding it to the hundreds using that:
rounder = int((number)*100)/100;
The problem is that sometimes, for example, it gives me 0.1 and i want 0.10... How can I easily add zeros automatically so I always have 2 decimal numbers?
Thanks
[MX04]rounding Dynamic Numbers
has anyone ever had the problem where they have a timer or health box and it's supposed to go to 45, but instead it goes to 44.99999999999999999999? i want to know if there is a way to prevent that, say tell the computer to always round to the nearest tenth. can someone help me? thanks.
Rounding Numbers In Dymanic Text?
First off I would like to say im using Flash 5 not 6, but Im sure there will be the same answer for both, just in case.
Im making a shooting game, its going great! I added an accuracy
stat to my shooting game, It works fine acept, seeing
Accuracy: 33.33333333
Is annonying how do I round the number or get rid of all the decimals?
Rounding Numbers Up Or Down On Decimal Integrer
Hi,
I have a challenging issue because Math.ceil and Math.floor rounds numbers to a whole number.
I am creating a dosage calculator and unfortunately I need to follow and produce existing values present on a printed sheet where the rounding does not happened in a straightforward manner. So I need to be able to round the numbers up or down in order to match existing values on the printed data sheet.
In one case, I have 6.251 as a result and I need to round it up to 6.3
In another case, I have 52.508 as a result and I need to round it down to 52.5
How can I accomplish this?
Thank you in advance.
Attila
FMX04 - Rounding Numbers (kind Of)
I have a problem for a project about numbers (standard deviations...)
How do i round the nubers to say 2 decimals, how do i cut out the rest of the
number from a dynamic field i'm using to display them...
example:
2.45727276566 to 2.45 (or 2.46 doesn't really matter in my case)
im used to using the standard syntax in cpp ("%.2f" or in flash i presume something
like variable_im_displaying.2 but it doesn't work
if anyone knows please help
Rounding Numbers, But It Ignores Zeros
This is really frustrating, trying to get a countdown going here showing minuites and seconds, ex 2.34 remaining
but when it counts down to for example 2.30 it shows 2.3 or 2.00 as 2..
spent a few hours on finding a solution now, cant crack this one..
Code:
function remaining() {
_root.tid = Number(_global.Behaviors.Sound.mySound.duration / 1000);
_root.pos = Number(_global.Behaviors.Sound.mySound.position / 1000);
_root.rem = ((_root.tid - _root.pos)+100)/100;
_root.remain = Math.round(_root.rem * Math.pow (10, 2)) / Math.pow (10, 2);
};
this.onEnterFrame = remaining;
FMX04 - Rounding Numbers (kind Of)
I have a problem for a project about numbers (standard deviations...)
How do i round the nubers to say 2 decimals, how do i cut out the rest of the
number from a dynamic field i'm using to display them...
example:
2.45727276566 to 2.45 (or 2.46 doesn't really matter in my case)
im used to using the standard syntax in cpp ("%.2f" or in flash i presume something
like variable_im_displaying.2 but it doesn't work
if anyone knows please help
Rounding Numbers (math.round Not Working)
I need to round some equation results, and math.round is not working for me. This is my basic equation and I get a NaN:
roundingdiff = (math.round(rdiff*1000))/1000;
Any help would be greatly appreciated. I know it's syntax, but I can't figure out what the correct syntax is.
Thanks!
Rounding Off Numbers In A Dynamic Text Field.
How do you control the decimals in a dynamic text field?
I would like to always have to decimals after a number in the text field, and also I want to be in control off how the decimals are rounded off...
Order Form, Help With Autofill Totals And Rounding Numbers
Actionscript novice here. I'm trying to make an order form that fills in the shipping, tax and totals once a book quantity is entered. I am having problems with rounding the numbers and don't know where to add the "RoundNumber" code in to make that work. Also for the variable tax I am having issues because the tax only applies if you live in IL otherwise there is no tax. Also my total doesn't seem to be working now, the code isn't adding the shipping tax and book price, just listing them side by side in the box. Any ideas? I feel like I'm getting close, but I just don't know how to fix it.
ActionScript Code:
function roundNumber(value) {
var rnum = value
var rlength = 2; // The number of decimal places to round to
if (rnum > 8191 && rnum < 10485) {
rnum = rnum-5000;
var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
newnumber = newnumber+5000;
} else {
var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
}
return(newnumber);
}
//set initial values at $0.00
nuts_bookqty.text = 0;
nuts_tax.text = 0;
nuts_shipping.text = 0;
nuts_total.text = 0;
//declare variables
var tax = 0;
if (nuts_state.selectedItem.label = "IL") {
var tax = .070;
}
else {
var tax = 0;
}
var shipping = 7.95
var bookcost = 49.95
var booktotal = 49.95*nuts_bookqty.text
//calculate
this.onEnterFrame = function (){
nuts_tax.text = "$" + Number(nuts_bookqty.text)*Number(bookcost)*Number(tax);
nuts_shipping.text = "$" + Number(nuts_bookqty.text)*Number(shipping);
nuts_total.text = "$"+ Number(booktotal) + Number(nuts_tax.text) + Number(nuts_shipping.text);
}
Thanks!
Test Equality Of Ip Numbers/ Non Existing Numbers
I'm building a site that recognizes the computer that enters. I've set a variable containing the ip adres, and i wanna ad a name to this.
So... when i say
if ip = 120.155.654.321-->flash tells me this is not a number.
if ip eq 120.155.654.321-->flash tells me this is not a word.
know any solutions???
thanx
sven
Converting Numbers To Numbers With Numerical Separators
So if I return 10000 as a number in flash, how can I convert it to 10,000?
or, 1000 - 1,000
or 1000000 - 1,000,000
These numbers are generated by a complicated math formula, so they can be ANY number...
Is there no way of doing this in Flash???
Rounding Down?
I need to round a number down. math.round, wont work as it rounds to the NEAREST *******. any ideas?
regards,
Rounding
i have a variable and its a non-integer say 9.1.
I want to be able to round this up to the nearest whole number.
if it was 9.9 it would be ok int(9.9)- up to 10, but 9.1 rounds down to 9 where i want it to be 10.
How can i do this?
Rounding
im not a newb but this question might be
so im wondering how do you round up a math problem to the nearest whole number
e.g.
7.3*number(roundUp)
Rounding
Hi there,
Can anyone tell me how to:
1. Round a variable to the nearest whole number
2. Round to the nearest 1000 (eg. 2562 becomes 3000).
Many thanks!
Rounding Down?
This is the code
Code:
strModifier.text = (strTotalScore.text - 10) / 2;
I need to know how to make the product rounded down. I want no decimal ever.
Rounding
I know that Math.round(); rounds to an integer. Is there a function that rounds to a certain significant digit (or a specified digit after the decimal point)?
Rounding
Is there a way, or even better a class available in flash to help me round a number to a specific point. For example, I have need to have a number rounded to the nearest 15th, how would I do that?
Thanks in advance - Nukes
Rounding
Can you round to the tenths in flash. like Math.round(0.1344)
:dr ool::k ir:
Rounding
is there an easy way to specify how many digits after the decimal flash will return in a variable. I know you can do it in a sort of complicated way like this:
ActionScript Code:
//say i want 3 decimal places out of numbernumber = 100.12345number *= 1000;Math.round(number);number /= 1000;
but is there a better way, something like
Math.roundPlaces(number, 3);
?
thanks
Rounding Up [AS2]
how do I round up numbers with AS 2.0?
I have a textfield where im displaying the result of a calculation and i need only 2 digits after the "."
so instead of 23.0865 i would have 23.09
pretty sure this is simple but u guys know how it is .. hehe
thank you in advance
Rounding Decimals? Is It Possible?
I have a little script that displays my mouse coordinates, but I'm wondering if it's possible to round or eliminate the decimals, and just display whole numbers?
If anyone can help, thanks.
http://www.geocities.com/remmus16/dj/
you can see it in the upper left corner...
Rounding Variables
I have a simple preload script (see below) but the problem is that it returns a result with heaps of decimal places like 11.3694%.
FRAME 1:
percent = (_framesloaded/_totalframes)*100;
FRAME 2:
if (percent == 100) {
gotoAndPlay (21);
} else {
gotoAndPlay (1);
}
How do i go about making the variable round to the nearest whole number or something like that?
STOP PRESS....
OK, KIND OF SOLVED .... IN A WAY .....
I added this script:
percent = (_framesloaded/_totalframes)*100;
if (percent<10) {
display = 10;
} else if (percent<20) {
display = 20;
} else if (percent<30) {
display = 30;
} else if (percent<40) {
display = 40;
} else if (percent<50) {
display = 50;
} else if (percent<60) {
display = 60;
} else if (percent<70) {
display = 70;
} else if (percent<80) {
display = 80;
} else if (percent<90) {
display = 90;
} else if (percent<=100) {
display = 100;
} else {
display = error;
}
[Edited by Candrias77 on 09-18-2001 at 12:21 AM]
Rounding Off Schmounding Off
I am building a pre loader with heaps of stats and stuff, and need a simple query answered.
I need to know how to round off a number (or variable) to a certain amount of decimal places. I know how to round it off to a whole number.
Code:
kbs = (Number(loadedbytes)/Number(timeelapsed)/1000);
yeah i wanna round that ^^^^^ off to 2 decimal places instead of 6 million decimal places.
thanx a million in advance.
Rounding Off Decimals
ok i have in flash a gallon converter, it is length X width X height / 231, i usually end up with a decimal, how do i get rid of the decimal places?
|