The rounding functions round and formatnumber in ASP

Source: Internet
Author: User

ASP has two functions that can be used as rounding functions: the round function and the formatnumber function.

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.

Formatnumber Function

Formatnumber (expression [, digit [, leadingdigit [, Paren [, groupdigit].

Parameters

Expression
Required.

Digit indicates the number of digits displayed on the right of the decimal point. The default value is-1, indicating that the computer's regional settings are used.
Leadingdigit indicates the number of digits displayed on the right of the decimal point. The default value is-1, indicating that the computer's regional settings are used.
Paren indicates the number of digits to the right of the decimal point. The default value is-1, indicating that the computer's regional settings are used.
Groupdigit indicates the number of digits to the right of the decimal point. The default value is-1, indicating that the computer's regional settings are used.

Example

Example: <% = round (3.14159, 2) %>
Result: 3.14

Example: <% = formatnumber (45.324567, 3) %>
Result: 45.325

Differences

Although the round function is called a rounding function, what he calls rounding is not the same as what we usually call it. What we usually say is: a number greater than or equal to 5 is included and a value less than 5. However, the round function is an integer greater than 5, a value less than 5, and an odd number into an even number if the value is 5.

Example

Round (1.5)
Round (2.5)
Round (3.5)
Round (4.5)

Formatnumber (1.5, 0)
Formatnumber (2.5, 0)
Formatnumber (3.5, 0)
Formatnumber (4.5, 0)

The result of round is:
2
2
4
4

The result of formatnumber is:
2
3
4
5

It seems that if you really want to use the rounding function, it is more accurate to use the formatnumber!

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.