Number data types store numeric values. They are immutable data types. This means, changing the value of a number data type results in a newly allocated object.
Number objects are created when you assign a value to them. For example −
int intnum = 1; flt fltnumber = 10.0;
Spla supports different numerical types −
int (signed integers) − They are often called just integers or ints. They are positive or negative whole numbers with no decimal point.
flt (floating point real values) − Also called floats, they represent real numbers and are written with a decimal point dividing the integer and the fractional parts. Floats may also be in scientific notation, with E or e indicating the power of 10 (2.5e2 = 2.5 x 102 = 250).
It is possible to represent an integer in hexa-decimal or octal form
## number = 0xA0F !!Hexa-decimal ##<<number 2575 ## number = 0o37 !!Octal ##<<number 31
Here are some examples of numbers.
| int | float |
|---|---|
| 10 | 0.0 |
| 100 | 15.20 |
| -786 | -21.9 |
| 080 | 32.3+e18 |
| -0490 | -90. |
| -0×260 | -32.54e100 |
| 0×69 | 70.2-E12 |
Spla converts numbers internally in an expression containing mixed types to a common type for evaluation. Sometimes, you need to coerce a number explicitly from one type to another to satisfy the requirements of an operator or function parameter.
Type int(x) to convert x to a plain integer.
Type flt(x) to convert x to a floating-point number.