Skip to main content Link Search Menu Expand Document Toggle dark mode Copy Code (external link)

int() : Convert to Integer

Convert a value to a 32-bit integer. Truncates decimal values.


On this page

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

<p>Value: {{int(model.stringValue)}}</p>

Data:

doc.Params["model"] = new {
    stringValue = "42"
};

Output:

<p>Value: 42</p>

Truncate Decimal

<p>Truncated: {{int(model.decimalValue)}}</p>

Data:

doc.Params["model"] = new {
    decimalValue = 19.95m
};

Output:

<p>Truncated: 19</p>

Calculate Whole Units

<p>Full boxes: {{int(model.items / model.boxSize)}}</p>
<p>Remaining items: {{model.items % model.boxSize}}</p>

Data:

doc.Params["model"] = new {
    items = 47,
    boxSize = 12
};

Output:

<p>Full boxes: 3</p>
<p>Remaining items: 11</p>

Age Calculation

<p>Age: {{int(daysBetween(model.birthDate, model.today) / 365)}} years</p>

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

See Also