Int - VBScript


Overview

Int converts a number to an integer (whole number). It is commonly used to round off fractional values or extract the integer part of a number.

Syntax

Int(number)

| Argument | Description |
|—|—|
| number | The number to convert to an integer. Can be a numeric expression. |

Examples

' Round off a decimal value to an integer
Dim value = 12.5
Dim rounded = Int(value) ' rounded = 12

' Extract the integer part of a decimal
Dim value = 23.98
Dim integerPart = Int(value) ' integerPart = 23

Common Issues

  • Negative numbers: Int rounds towards zero, so for negative numbers, it will truncate the fractional part (e.g., Int(-12.5) results in -12).
  • Non-numeric input: If the input is not a valid number, an error will occur (e.g., Int("abc") is invalid).

Integration

Int can be used with other VB Script functions and operators, such as:

  • Round: to round off a number to a specific number of decimal places.
  • Math.Floor: to round off a number down to the nearest integer.
  • Math.Ceiling: to round off a number up to the nearest integer.
  • Fix: Converts a number to a fixed-point decimal.
  • Round: Rounds a number to the nearest whole number or to a specific number of decimal places.
  • Math.Floor: Rounds a number down to the nearest integer.
  • Math.Ceiling: Rounds a number up to the nearest integer.