Forgot username/password? Don't have an account?
Login with Facebook
Home » Courses » Coding Basics 2 » Numbers, int And unit
Subscribe for updates.
* New to us? log in with Facebook and get a free day pass

Numbers, int And unit

Are you ready to learn two new variable types and compare them to the Number data type? There are three types of numbers in ActionScript 3.0 : Number, int and uint. What are they and when should we use them?

We have seen how to deal with variables and operators in this course. Now let's take a look at data types associated with these variables to wrap up the coding basics. There are a number of data types that can be worked with according to our need. But as of now, it's enough to understand about a few numeric data type such as Number, int and uint.

Numbers

Number is a common word we used till now. The use of this data type was explained before when we started working with variables. As we all know, Number is a data type used to declare a variable of type Number (such a 1.13 or 999.) We know the difference between a string and a number, and the fact that data type mismatches can cause errors. Now we will learn what happens if the number used is a floating point number. A floating point number has a decimal value, for example 3.33 or 999.99999. Number refers to a floating point value by default. No need to worry if the output is a floating point value because if the variable was declared as Number, the application reserves memory for the decimal values as well.

Int and uint

We know that a lot of memory is used for a Number because of that decimal point; if we know that the value used will always be an integer, then the memory reserved for the decimal points is of no use. In that case, we can use the keyword int to declare an integer variable: var b:int; This will reserve memory for a single integer and displays the same. it's also useful when the output is a floating point value (say 3.33333) and we don't want the decimal points to be shown on the output panel. For this to happen, we must declare the variable as data type int. This will not only save memory but will also round off the output to an integer (in this case 3.3333 rounded off to 3.) But this works only when you already know that the numbers you're dealing with are integers.

There are also a few possibilities where we not only need an integer but a positive integer. These situations are rare; so for the most part you should always use int unless you need to access really large numbers. As int stores both positive and negative numbers, the amount of numbers int can show is exactly 50% of what the unit can. Don't use uint unless you need to access really big numbers. Why do we say that? Mainly because if you put inside a uint the value '-5' you'll find a totally different number in it as it's out of bounds: the actual number that will be in it will be the maximum number -5 (and that is a very very big number.)

Got A Question?

'I love being Prime'

Have a question but don't want to ask it publicly? If you are a prime member just ask right here and we will get back to you within 48 hours. Not prime yet? no worries you can ask publicly below.

Act now while we have available seating

Our on line school is private, affordable and interactive with trainer support.
Act now save your seat before someone else takes yours.
Act now