ASP Math FunctionMath 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.
Mod function to get the reminder of divisionWe can get the reminder after a division is by using mod function. Here is the code
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 round function to format decimal placeRound function is used to round of a number and format the number as per requirement.
We can format a number as per requirement of decimal place. For example we want the number should display two decimal places only.
The above line is rounded off to two decimal place.
ASP Random number generatorWe 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
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.
ASP percentage value by using FormatPercent functionWe can get the percentage of two numbers by using ASP function FormatPercent(). We can use this function to get the percentage and we can format the output as per our requirement. Here is the syntax of FormatPercent function.
Here n1 and n2 are two variables and d3 is the number specifying number of decimal places required. d3 is an optional value we can specify as the number of decimal places we want. Default value for this is 2.
Here is an example of FormatPercent function.
one more example without using optional value for decimal places
This article is written by plus2net.com team.
Be the first to post comment on this article : |