VBScript provides numeric functions and operators that Classic ASP pages can use for rounding, integer calculations, remainders, pseudo-random values and formatted percentages.
Int(4.0) = 4
Int(4.1) = 4
Int(4.9) = 4
Int(4.5) = 4
Int(1.1) = 1
Int(0) = 0
Int(-0.1) = -1
Int(-2.1) = -3
Int(-2.9) = -3
Int() returns the greatest integer less than or equal to the value, so negative numbers move toward negative infinity rather than simply losing their decimal part.
Dim myNum1, myNum2
myNum1 = 50
myNum2 = 10
Response.Write myNum1 Mod myNum2
The result is 0. Changing myNum1 to 55 produces 5.
Round(5.768) = 6
Round(5.368) = 5
Round(0.768) = 1
Round(-3.368) = -3
Round(5.768, 2) = 5.77
Round() uses banker's rounding in midpoint cases. Do not assume that every value ending exactly in 5 rounds away from zero.Dim myNum
Randomize
myNum = Int((Rnd * 10)) + 1
Response.Write myNum
Rnd returns a pseudo-random value greater than or equal to 0 and less than 1. Randomize initializes the generator, normally from the system timer.
Dim myNum, maxValue, minValue
maxValue = 5
minValue = 2
Randomize
myNum = Int((maxValue - minValue + 1) * Rnd + minValue)
Response.Write myNum
Rnd() is suitable for ordinary display/demo randomness, not for passwords, reset tokens, session identifiers or other security-sensitive values.FormatPercent(expression, numDigitsAfterDecimal)
FormatPercent() multiplies the value by 100, formats it as a percentage and adds the percent symbol. If the decimal-place argument is omitted, formatting follows the server's regional settings rather than a guaranteed fixed two-decimal default.
Dim myPercent
myPercent = FormatPercent(11 / 203, 6)
Response.Write myPercent 'Example: 5.418719%
Dim myPercent
myPercent = FormatPercent(11 / 203)
Response.Write myPercent 'Exact formatting follows regional settings
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.