This article mainly introduces the integer division and remainder methods in ASP (VBScript). Friends who need it can refer to it.
Divisible
In ASP (VBScript), / is used for integer division, for example, m = 5 / 2, the result is 2.
Take remainder
Use mod to get remainder in ASP(VBScript), for example, m = 5 mod 2, the result is 1.
Pay attention to the majority
m = 4444444444 / 2
n = 4444444444 / 2
The first sentence is correct, but an overflow error will be reported when the second sentence is run because: before the integer division and remainder operations, the numerical expression is rounded to a Byte, Integer or Long subtype expression. The range of the Long subtype is [-2147483648, 2147483647], that is, the number to enter the integer division or remainder must be within this range.
Several rounding functions in asp
Several rounding functions in asp are: fix(), int(), round();
The Int(number) and Fix(number) functions return the integer part of a number. The number parameter can be any valid numeric expression. If the number parameter contains Null, Null is returned.
example:
Copy the code code as follows:
response.write int(2.14) '2
response.write fix(2.14) '2
response.write int(2.54) '2
response.write int(2.54) '2
Both the Int and Fix functions remove the decimal part of the number argument and return the result as an integer. The difference between the Int and Fix functions is that if the number parameter is a negative number, the Int function returns the first negative integer less than or equal to number, while the Fix function returns the first negative integer greater than or equal to the number parameter. For example, Int converts -8.4 to -9, and the Fix function converts -8.4 to -8.
round(Expression[, numdecimalplaces]) returns a number rounded to the specified number of digits. Expression is required. Numeric expressions are rounded. Numdecimalplaces are optional. The number indicates how many digits to the right of the decimal point are used for rounding. If omitted, the Round function returns an integer.
example:
Copy the code code as follows:
response.write round(3.14) '3
response.write round(3.55) '4
response.write round(3.1415,3) ' 3.142
Test code:
- <%
- response.write650/100&<br>
- response.writeint(650/100)&<br>
- response.writefix(650/100)&<br>
- response.writeint(2.54)&<br>
- response.writeint(2.54)&<br>
- %>