int() : Convert to Integer
On this page
Summary
Convert a value to a 32-bit integer. Truncates decimal values.
Alias: integer()
Signature
int(value)
integer(value)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
value |
Any | Yes | The value to convert to integer |
Returns
Type: Int32
A 32-bit integer representation of the value.
Examples
Convert String to Integer
Data:
doc.Params["model"] = new {
stringValue = "42"
};
Output:
<p>Value: 42</p>
Truncate Decimal
Data:
doc.Params["model"] = new {
decimalValue = 19.95m
};
Output:
<p>Truncated: 19</p>
Calculate Whole Units
Data:
doc.Params["model"] = new {
items = 47,
boxSize = 12
};
Output:
<p>Full boxes: 3</p>
<p>Remaining items: 11</p>
Age Calculation
Data:
doc.Params["model"] = new {
birthDate = new DateTime(1990, 5, 15),
today = new DateTime(2024, 3, 15)
};
Output:
<p>Age: 33 years</p>
Notes
- Truncates decimal places (does not round)
- Handles string-to-integer conversion
- Throws exception if value cannot be converted
- For rounding instead of truncating, use
round()function - Range: -2,147,483,648 to 2,147,483,647
- For larger values, use
long()function - Alias
integer()provides same functionality