Round, fix, int function Miscellaneous

Source: Internet
Author: User

Round Function
Returns the value rounded to the specified number of digits.

Round (expression [, numdecimalplaces])

Parameters
Expression

Required. The numeric expression is rounded down.

Numdecimalplaces

Optional. Number indicates the number of digits to the right of the decimal point. If this parameter is omitted, the round function returns an integer.

Description
The following example uses the round function to round a value to two decimal places:

Dim myvar, Pi
Pi = 1, 3.14159
Myvar = round (PI, 2) 'myvar contains 3.14.

INT and fix Functions
Returns the integer part of a number.

INT (number)

Fix (number)

The number parameter can be any valid numeric expression. If the Number Parameter contains null, null is returned.

Description
Both the int and fix functions Delete the fractional part of the Number Parameter and return the result expressed as an integer.

The difference between the int and fix functions is that if the number parameter is negative, the int function returns the first negative integer less than or equal to the number, and 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.

Fix (number) is equivalent:

The following example of SGN (number) * int (ABS (number) shows how the int and fix functions return the integer part of a Number:

Mynumber = int (99.8) 'returns 99.
Mynumber = fix (99.2) 'returns 99.
Mynumber = int (-99.8) 'returns-100.
Mynumber = fix (-99.8) 'returns-99.
Mynumber = int (-99.2) 'returns-100.
Mynumber = fix (-99.2) 'returns-99.

Problem:
Try the followingCode:
Response. wriet (role (4.5 ))
Response. wriet (role (4.6 ))
Response. wriet (role (3.5 ))
Response. wriet (role (2.5 ))
Response. wriet (role (1.5 ))

What is your result?

Result:
4
5
4
2
2

Well! It seems wrong? There is a problem with the rounding result of 4.5 and 2.5. Is it an ASP bug?

Slow... This is a misunderstanding!

What do you say when reading a book:
When the round function is positioned as 5, it determines the rounding result based on the parity of the previous number,
When the value is an odd number, it is an even number.

Now you should understand why the above results are displayed.
But the problem persists,
1. What does ASP ask?
2. What should I do if I want to rounding up the numbers?

Don't worry.
1. Reasons for ASP Processing
ActuallyProgramMost of the rounding in is not rounded in, but 1-4, 6-9, and 5 returns the nearest even number. This is a financial requirement, because the rounding ratio is 4/5, not average, and is very important in finance, only the nearest even number of 5 can be equal in probability.
2. You can use formatnumber
Example:
Formatnumber (1.5, 0)
Formatnumber (2.5, 0)
Formatnumber (3.5, 0)
Formatnumber (4.5, 0)
You can also use the fix and INT functions to intercept the integer part of a number.

Haha !!! This problem has been solved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.