A Flash Developer Resource Site

# Thread: Finding remainders and assigning variables

1. ## 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.

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

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  Reply With Quote

2. 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
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
trace ("Number after decimal point");
trace (roundeddecimal2);  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap 