Free Guides
Language Tutorials

ASP ( Active Server Pages )
Index

MATH FUNCTIONS
ASP round function to format decimal place in ASP
Round function is used to round of a number and format the number
as per requirment.
Round(5.768) will return 6
Round(5.368) will return 5
Round(0.768) will return 1
Round(-3.368) will return -3
We can format a number as per requirement of decimal place. For
example we want the number should display two decimal places only.
Round(5.768,2) will return 5.77
ASP Math Function
Math functions are part of our ASP scripts. Mostly they are used
within the applications and support the script with various
features. We will discuss some common functions used frequently
inside our code.
Int function to get Integer part
From any number we can get the integer part only by using int
function . Here are some values returned by int function
Int ( 4.1 ) will return 4
Int ( 4.9 ) will return 4
Int ( 4.5 ) will return 4
Int ( 1.1 ) will return 1
Int ( 0 ) will return 0
Int ( -0.1 ) will return -1
Int ( -2.1 ) will return -3
Int ( -2.9 ) will return -3
Mod function to get the reminder of division
We can get the reminder after a division is by using mod
function. Here is the codeDim
my_num1,my_num2
my_num1=50
my_num2=10
Response.Write my_num1 mod my_num2
The output of above line is 0. If we change the value of
my_num1 to 55 then the output will change to 5.
ASP Random number generator
We can generate random number for our applications using ASP. The
random number can be used for displaying random images, or random
banners or random colors for a page or random numbers for any type
of application. To generate random number we have to initiate random
number generator first by using randomize function. Here is
the code to generate random number between 1 and 10
Dim my_num
Randomize
my_num = Int((rnd*10))+1
Response.Write my_num
The function rnd returns random number between 0 and .9 so
we have multiplied it by 10 to move the decimal place one step
right. Then took the integer part by using
Int function, then we have added 1 to it.
We can also give a range of number and generate random number
between the given maximum and minimum numbers. Here is the code.
max=5
min=2
Randomize
my_num=int((max-min+1)*rnd+min)
Response.Write my_num