This article mainly introduces the method of retaining two digits after the decimal point in ASP, which is implemented using the FormatNumber function. Friends in need can refer to the following
Recently, I have used ASP programs to process some data forms, and I have encountered digital formatting problems, such as how many decimal places should be retained in the data. After research, I can use ASP's built-in function FormatNumber to achieve this. Let's talk about how to use the FormatNumber function in detail.
FormatNumber function: Returns an expression formatted as a number.
parameter:
Expression
Required. The expression to format.
NumDigitsAfterDecimal
Optional. A numeric value indicating the number of digits displayed to the right of the decimal point. The default value is -1, which means use the computer's regional settings.
IncludeLeadingDigit
Optional. A three-state constant that indicates whether leading zeros for decimal values are displayed. For specific values, see "Settings".
UseParensForNegativeNumbers
Optional. Three-state constant indicating whether to place negative values within parentheses. For specific values, see "Settings".
GroupDigits
Optional. A three-state constant that indicates whether numbers are grouped using the group separator specified in the locale. For specific values, see "Settings".
set up:
The IncludeLeadingDigit, UseParensForNegativeNumbers, and GroupDigits parameters have the following settings:
Constant description
TriState.True True
TriState.False False
TriState.UseDefault The locale of the computer
exception/error
Exception type error number condition
InvalidCastException 13 The type is not a number.
Remark:
When one or more optional parameters are omitted, the values of the omitted parameters are provided by the locale.
Notice:
All setting information comes from the application's locale settings. By default, this information is the locale set in Control Panel. However, it can be changed programmatically by using the .NET Framework.
To enumerate:
Keep 2 decimal places: <%=FormatNumber(123.12345,2)%>, output result: 123.12