| パッケージ | トップレベル |
| public final class int | |
| 継承 | int Object |
int クラスのプロパティは静的であるため、プロパティを使用するためのオブジェクトは不要で、コンストラクタを使用する必要はありません。ただし、メソッドは静的でないため、メソッドを使用するためのオブジェクトは不要です。int オブジェクトは、int クラスコンストラクタを使用するか、int 型の変数を宣言してその変数にリテラル値を割り当てることによって作成することができます。
int データ型は、ループカウンタおよび浮動小数の不要なその他の状況に効果的で、Java および C++ の int データ型と似ています。int 型変数のデフォルト値は 0 です。
int.MAX_VALUE を超える数値を処理する場合には、Number を使用することを検討してください。
次の例では、int クラスの toString() メソッドを呼び出します。このメソッドは、ストリング 1234 を返します。
var myint:int = 1234; myint.toString();
次の例では、コンストラクタを使用せずに、MIN_VALUE プロパティの値を宣言された変数に割り当てます。
var smallest:int = int.MIN_VALUE;
関連項目
| メソッド | 定義 | ||
|---|---|---|---|
|
コンストラクタ; 新しい int オブジェクトを作成します。
| int | ||
![]() |
指定されたプロパティがオブジェクトに定義されているかどうかを示します。
| Object | |
![]() |
Object クラスのインスタンスが、パラメータとして指定されたオブジェクトのプロトタイプチェーン内にあるかどうかを示します。
| Object | |
![]() |
指定されたプロパティが存在し、列挙できるかどうかを示します。
| Object | |
![]() |
ループ処理に対するダイナミックプロパティの可用性を設定します。
| Object | |
|
数値のストリング表現を指数表現で返します。
| int | ||
|
数値のストリング表現を固定小数点表現で返します。
| int | ||
|
数値のストリング表現を指数表現または固定小数点表現で返します。
| int | ||
int オブジェクトのストリング表現を返します。 | int | ||
|
指定された int オブジェクトのプリミティブな値を返します。
| int | ||
| 定数 | 定義 | ||
|---|---|---|---|
| MAX_VALUE : int = 2147483647 [static]
表現可能な 32 ビット符号付き整数の最大値、2,147,483,647 です。
| int | ||
| MIN_VALUE : int = -2147483648 [static]
表現可能な 32 ビット符号付き整数の最小値、-2,147,483,648 です。
| int | ||
| int | () | コンストラクタ |
public 関数 int(num:Object)
コンストラクタ; 新しい int オブジェクトを作成します。int.toString() と int.valueOf() を使用するには、int コンストラクタを使用する必要があります。int オブジェクトのプロパティを使用する場合は、コンストラクタを使用しません。new int コンストラクタは、主にプレースホルダーとして使用します。int オブジェクトは、パラメータをプリミティブ値に変換する int() 関数とは異なります。
num:Object — 作成する int オブジェクトの数値、または数値に変換する値です。value が指定されなかった場合のデフォルト値は 0 です。
|
関連項目
var n1:int = new int(3.4); var n2:int = new int(-10);
| toExponential | () | メソッド |
AS3 function toExponential(fractionDigits:uint):String
数値のストリング表現を指数表現で返します。ストリングには、fractionDigits パラメータでの指定に従って小数点の前に 1 桁、小数点以下に最大 20 桁が含まれます。
fractionDigits:uint — 必要な小数の桁数を表す 0 ~ 20 の整数です。
|
String |
RangeError — fractionDigits 引数が 0 ~ 20 の範囲外である場合に、例外をスローします。
|
toExponential(2) returns a string in exponential notation. var num:Number = 315003; trace(num.toExponential(2)); // 3.15e+5
| toFixed | () | メソッド |
AS3 function toFixed(fractionDigits:uint):String
数値のストリング表現を固定小数点表現で返します。固定小数点表現とは、fractionDigits パラメータでの指定に従って、小数点以下の特定数の桁をストリングに含めたものです。fractionDigits パラメータの有効範囲は 0 ~ 20 です。この範囲外の値を指定すると例外がスローされます。
fractionDigits:uint — 必要な小数の桁数を表す 0 ~ 20 の整数です。
|
String |
RangeError — fractionDigits 引数が 0 ~ 20 の範囲外である場合に、例外をスローします。
|
toFixed(3) returns a string that rounds to three decimal places. var num:Number = 7.31343; trace(num.toFixed(3)); // 7.313
toFixed(2) returns a string that adds trailing zeroes. var num:Number = 4; trace(num.toFixed(2)); // 4.00
| toPrecision | () | メソッド |
AS3 function toPrecision(precision:uint):String
数値のストリング表現を指数表現または固定小数点表現で返します。ストリングには、precision パラメータで指定された桁数が含まれます。
precision:uint — 結果のストリングに必要な桁数を表す 1 ~ 21 の整数です。
|
String |
RangeError — precision 引数が 1 ~ 21 の範囲外である場合に、例外をスローします。
|
toPrecision(3) returns a string with only three digits. The string is in fixed-point notation because exponential notation is not required. var num:Number = 31.570; trace(num.toPrecision(3)); // 31.6
toPrecision(3) returns a string with only three digits. The string is in exponential notation because the resulting number does not contain enough digits for fixed-point notation. var num:Number = 4000; trace(num.toPrecision(3)); // 4.00e+3
| toString | () | メソッド |
AS3 function toString(radix:uint):String
int オブジェクトのストリング表現を返します。
radix:uint — 数値からストリングへの変換に使用する基数 (2 ~ 36) を指定します。radix パラメータを指定しない場合、デフォルト値は 10 です。
|
String —
ストリング。
|
radix パラメータに 2 および 8 を使用し、数値 9 に対応する表現を含むストリングを返します。
var myint:int = new int(9); trace(myint.toString(2)); // output: 1001 trace(myint.toString(8)); // output: 11
次の例では、結果が 16 進数値になります。
var r:int = new int(250); var g:int = new int(128); var b:int = new int(114); var rgb:String = "0x"+ r.toString(16)+g.toString(16)+b.toString(16); trace(rgb); // 0xfa8072
| valueOf | () | メソッド |
AS3 function valueOf():int指定された int オブジェクトのプリミティブな値を返します。
戻り値int —
int 値です。
|
numSocks オブジェクトのプリミティブな値が結果として返されます。
var numSocks:int = new int(2); trace(numSocks.valueOf()); // 2
| MAX_VALUE | 定数 |
public static const MAX_VALUE:int = 2147483647表現可能な 32 ビット符号付き整数の最大値、2,147,483,647 です。
trace("int.MIN_VALUE = "+int.MIN_VALUE);
trace("int.MAX_VALUE = "+int.MAX_VALUE);
このコードは、次の値を記録表示します。
int.MIN_VALUE = -2147483648 int.MAX_VALUE = 2147483647
| MIN_VALUE | 定数 |
public static const MIN_VALUE:int = -2147483648表現可能な 32 ビット符号付き整数の最小値、-2,147,483,648 です。
trace("int.MIN_VALUE = "+int.MIN_VALUE);
trace("int.MAX_VALUE = "+int.MAX_VALUE);
このコードは、次の値を記録表示します。
int.MIN_VALUE = -2147483648
int.MAX_VALUE = 2147483647
IntExample class to show how to work with and check the validity of int data types: a and b are declared in the constructor.addIntegers().c is assigned the outcome of parseInteger(), which checks the validity of the string passed to it to ensure that it is an integer value in the acceptable range for int data types and returns an int equal to the integer value of the string if it is valid.a and c are added together using addIntegers(). package { import flash.display.Sprite;
public class IntExample extends Sprite { public function IntExample() { var a:int = 512; var b:int = -128;
trace(addIntegers(a, b)); // 384
var c:int = parseInteger("32");
trace(addIntegers(a, c)); // 544 }
public function addIntegers(a:int, b:int):int { return a + b; }
public function parseInteger(str:String):int { var num:Number = parseInt(str); if(!isNaN(num) && num <= int.MAX_VALUE && num >= int.MIN_VALUE) { return int(num); }
return 0; }
} }