Skip to Content
ActionScript: The Definitive Guide
book

ActionScript: The Definitive Guide

by Colin Moock
May 2001
Intermediate to advanced
720 pages
23h 24m
English
O'Reilly Media, Inc.
Content preview from ActionScript: The Definitive Guide

Name

int( ) Global Function — truncate the decimal portion of a number

Availability

Flash 4; deprecated in Flash 5 in favor of analogous Math methods

Synopsis

int(number)

Arguments

number

A number or an expression that yields a number, typically a number with a fractional (decimal) portion.

Returns

The integer portion of number.

Description

The int( ) function was used in Flash 4 as a brute-force means of extracting the integer portion of a number. It effectively rounds positive numbers down and rounds negative numbers up. The int( ) function works only for numbers in the range -2147483648 (-231) to 2147483647 (231-1); it produces undefined results for numbers outside this range. If number is a string composed of only numbers, int( ) converts the string to a number before operating on it. If number is the Boolean value true, int( ) returns the value 1. For all other non-numeric data (including undefined and null), int( ) returns the value 0.

Usage

The int( ) function has been deprecated in favor of the more precise and standard Math.floor( ), Math.ceil( ), and Math.round( ) methods. Use parseInt( ) or Number( ) to convert non-numeric data to an integer or number.

Example

int(4.5)      // Yields 4
int(-4.5)     // Yields -4
int(3.999)    // Yields 3

The int( ) function is useful to check if a number is a whole number by comparing the original number to the result of the int( ) function:

if (int(x) != x) {
  trace ("Please enter a whole number for your age in years");
}

See Also

Math.ceil( ), Math.floor( ),

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Actionscript Cookbook

Actionscript Cookbook

Joey Lott

Publisher Resources

ISBN: 1565928520Catalog PageErrata