Returns an int from a specified value.
If no value is given, the default integer 0
is returned.
If the specified value was a float value, then the new integer value will be rounded towards zero.
If the specified value is of type str, then the initial characters
of the string are converted until a non-digit character is found.
Initial white space is ignored and the number may start with an optional +
or -
sign.
Type bool values are converted to 1
for true
and 0
for false
.
This function does not generate a change.
int(value)
Argument | Type | Description |
---|---|---|
value | any (optional) | The value where to create an integer value for. |
An integer value. In case the integer value is too large for a 64bit integer,
an overflow_err() is raised. Other type than float
, str
, bool
, datetime
, timeval
or int
will raise a bad_data_err().
This code shows some return values for int():
[
int(),
int(2.718),
int(-1.9),
int('365 days'),
int('0xFF'),
int(true),
int(false),
int(datetime('2013-06-02T00:00:00Z')),
];
Return value in JSON format
[
0,
2,
-1,
365,
255,
1,
0,
1370131200
]