-
Finding remainders and assigning variables
This is a flash AS3 related question.
Firstly let me start by saying these forums are great what a wealth of knowledge.
It is time for me to stop looking and start asking I'm afraid.
Please help an old fella out with a taxing question.
I wish to take a number
Example 2.1
And end up with two variables
1st variable containing the whole number and the second with the remainder.
Example
var one = 2
var two = 0.1
I have tried the following
var testnumber = 2.1
var rounded = Math.floor(testnumber);
trace("Rounded number");
trace(rounded );
var answer = testnumber - rounded
trace ("answer");
trace (answer);
but the remainder number comes out with 0.10000000000000009
Is there any way I can make this number become 0.1?
To make matters more complicated I also wish to work with negative numbers.
var testnumber = -1.4
i.e
var one = -1
var two = 0.4
the var testnumber could be anywhere between -10.0 and 50.0
Would this work the same as above if a solution could be found?
Any ideas?
Regards
Adey
Last edited by adey_flash; 06-28-2011 at 05:10 PM.
-
Never mind I figured it out. Fresh eyes and a new day helped.
// POSITIVE NUMBERS
var testnumber = 32.1
var rounded = Math.floor(testnumber);
trace ("Positive Numbers displayed and disected");
trace (" ");
trace ("Starting whole number");
trace(testnumber);
trace("Rounded Positive number");
trace(rounded);
var answer = testnumber - rounded
var roundeddecimal1 = Math.round(answer*100)/100
trace ("Number after decimal point");
trace (roundeddecimal1);
trace (" ");
trace (" ");
// NEGATIVE NUMBERS
var testnumber2 = -10.1
var rounded2 = Math.round(testnumber2);
trace ("Positive Numbers displayed and disected");
trace (" ");
trace ("Starting whole number");
trace(testnumber2);
trace("Rounded Positive number");
trace(rounded2);
var answer2 = testnumber2 - rounded2
var roundeddecimal2 = Math.round(answer2*100)/100
trace ("Number after decimal point");
trace (roundeddecimal2);
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
|