Method of preserving two digits after decimal point in ASP (using FormatNumber) _ Application Tips

Source: Internet
Author: User
Tags constant locale locale setting numeric value true true

Recently, using an ASP program to deal with some data forms, the problem of the number format, such as data retention of several decimal places, after research, you can use the ASP's built-in function FormatNumber to achieve, the following specifically said FormatNumber function use method.

FormatNumber function: Returns an expression formatted as a number.

Parameters:

Expression
Required option. The expression to format.
Numdigitsafterdecimal
Options available. Numeric value that indicates the number of digits displayed to the right of the decimal point. The default value is 1, which indicates the use of the computer's locale.
IncludeLeadingDigit
Options available. A three-state constant that indicates whether to display a leading zero for a decimal value. For specific values, see settings.
UseParensForNegativeNumbers
Options available. A three-state constant that indicates whether negative values are placed within parentheses. For specific values, see settings.
GroupDigits
Options available. A three-state constant that indicates whether numbers are grouped by using the group delimiter specified in the locale. For specific values, see settings.

Set up:

The IncludeLeadingDigit, useparensfornegativenumbers, and GroupDigits parameters have the following settings:
Constants Description
Tristate.true True
Tristate.false False
Tristate.usedefault your computer's locale
Exception/Error
Exception type error number condition
The InvalidCastException 13 type is not a number.

Note:

When one or more optional parameters are omitted, the value of the omitted parameter is provided by the locale setting.

Attention:

All settings information comes from the locale of the application. By default, this information is the locale set in Control Panel. However, you can make changes to it programmatically by using the. NET Framework.

To give a column:

Retains 2 decimal places: <%=formatnumber (123.12345,2)%> output: 123.12

Related Article

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.