There are two main types of numeric data in JScript:
Integers
Positive whole numbers, negative whole numbers, and the number zero are integers. They can be represented in base 10 (decimal), base 8 (octal), and base 16 (hexadecimal). Most numbers in JScript are written in decimal. Octal and hexadecimal rarely have any practical purpose in scripting; however, you should be aware of their denotation – particularly for octals, since it may cause unexpected results when a number is interpreted as an octal when it was supposed to be decimal.
You denote octal integers by prefixing them with a leading 0 (zero). They can only contain digits 0 through 7. Any number with a leading 0 will be interpreted as an octal, as long as it is not containing the digits 8 and/or 9, in which case it is interpreted as a decimal number.
You denote hexadecimal (hex) integers by prefixing them with a leading "0x" (zero and x or X). They can contain digits 0 through 9, and letters A through F (either uppercase or lowercase) only.
Both octal and hexadecimal numbers can be negative, but they cannot have a decimal portion and cannot be written in scientific (exponential) notation.
JScript .NET supports the following integral data types: byte, ushort, uint, ulong, sbyte, short, int, long. Variables of any integral data type can represent only a finite range of numbers. If you attempt to assign a numeric literal that is too large or too small to an integral data type, a type-mismatch error will be generated at compile time.
JScript value type |
Range |
byte (unsigned) |
0 to 255 |
ushort (unsigned short integer) |
0 to 65,535 |
uint (unsigned integer) |
0 to 4,294,967,295 |
ulong (unsigned extended integer) |
0 to approximately 1020 |
sbyte (signed) |
-128 to 127 |
short(signed short integer) |
-32,768 to 32,767 |
int (signed integer) |
-2,147,483,648 to 2,147,483,647 |
long (signed extended integer) |
Approximately -1019 to 1019 |
Floating Point Data
Floating-point values are whole numbers with a decimal portion. They can either be represented with digits followed by a decimal point. (“period”/”dot”) and more digits (e.g. 1.29384), or they can be expressed in scientific notation; that is, an uppercase or lowercase letter e is used to represent "times ten to the power of" (e.g. 7.64e3). A number that begins with a single 0 and contains a decimal point is interpreted as a decimal floating-point literal and not an octal literal .
Additionally, floating-point numbers in JScript can represent special numerical values that integral data types cannot. These are:
- NaN(not a number). This is used when a mathematical operation is performed on inappropriate data, such as strings or the undefined value.
- Infinity. This is used when a positive number is too large to represent in JScript.
- -Infinity (negative Infinity). This is used when the magnitude of a negative number is too large to represent in JScript.
- Positive and Negative 0. JScript differentiates between positive and negative zero.
JScript supports the following floating-point data types:
JScript value type |
Range |
float(single-precision floating-point) |
The float type can represent numbers as large as 1038 (positive or negative) with an accuracy of about seven digits, and as small as 10-44. The float type can also represent NaN (Not a Number), positive and negative infinity, and positive and negative zero. This type is useful for large numbers where you do not need precise accuracy. If you require very accurate numbers, consider using the Decimal data type. |
Number , double (double-precision floating-point) |
The Number or double type can represent numbers as large as 10308 (positive or negative) with an accuracy of about 15 digits, and as small as 10-323. The Number type can also represent NaN (Not a Number), positive and negative infinity, and positive and negative zero. This type is useful when you need large numbers but do not need precise accuracy. If you require very accurate numbers, consider using the Decimal data type. |
decimal |
The decimal type can accurately represent very large or very precise decimal numbers. Numbers as large as 1028 (positive or negative) and with as many as 28 significant digits can be stored as a decimal type without loss of precision. This type is useful when rounding errors must be avoided. The decimal data type cannot represent NaN, positive Infinity, or negative Infinity. |