Flash / Flex / ActionScript/Data Type/parseInt
Содержание
- 1 If omitted, the radix is assumed to be 10, unless the string starts with 0x, 0X, or 0
- 2 Octal is treated as a decimal number, not an octal number:
- 3 Parse the numbers from the string base-10
- 4 Parse the numbers from the string base-16 (hexadecimal)
- 5 Parse the numbers from the string in base-2 (binary)
- 6 When the number is treated base-10, conversion stops when a non-numeric character is encountered
If omitted, the radix is assumed to be 10, unless the string starts with 0x, 0X, or 0
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ trace(parseInt("0x12")); // The radix is implicitly 16. Displays: 18 trace(parseInt("017")); // The radix is implicitly 8. Displays: 15 } }
}
</source>
Octal is treated as a decimal number, not an octal number:
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ // The number is treated as a decimal, not an octal number trace(parseInt("017", 10)); // Displays: 17 (not 15) } }
}
</source>
Parse the numbers from the string base-10
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ trace(parseInt("17", 10)); // Displays: 17 } }
}
</source>
Parse the numbers from the string base-16 (hexadecimal)
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ trace(parseInt("19", 16)); // Displays: 25 } }
}
</source>
Parse the numbers from the string in base-2 (binary)
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ trace(parseInt("110011", 2)); // Displays: 51 } }
}
</source>
When the number is treated base-10, conversion stops when a non-numeric character is encountered
<source lang="java">
package{
import flash.display.Sprite; public class Main extends Sprite{ public function Main(){ // The number is treated as a decimal, not a hexadecimal number trace(parseInt("0x12", 10)); // Displays: 0 (not 12 or 18) } }
}
</source>