VBScript Math Functions in Classic ASP

VBScript provides numeric functions and operators that Classic ASP pages can use for rounding, integer calculations, remainders, pseudo-random values and formatted percentages.

Int(): round down to an integer

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.

Mod: get the remainder

Dim myNum1, myNum2
myNum1 = 50
myNum2 = 10
Response.Write myNum1 Mod myNum2

The result is 0. Changing myNum1 to 55 produces 5.

Round(): decimal places

Round(5.768) = 6
Round(5.368) = 5
Round(0.768) = 1
Round(-3.368) = -3
Round(5.768, 2) = 5.77
VBScript/VBA Round() uses banker's rounding in midpoint cases. Do not assume that every value ending exactly in 5 rounds away from zero.

Pseudo-random numbers with Rnd()

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()

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

ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer