Format numbers using FormatNumber () and FormatPercent ()

Source: Internet
Author: User
VBScript has two negative numbers that are used to format numbers. with function FormatNumber (), you can specify the number of digits to display after the decimal point, whether to display a leading 0, whether to use spaces when negative numbers are used, and whether to use separators, and so on. Here are some examples and their return values:
<%=formatnumber (6665.8999)%>
6,665.90
<%=formatnumber ("6665.8999")%>
6,665.90
<%=formatnumber (6665.8999,3)%>
6,665.900
<%=formatnumber ( -6665.8999,3,-1,-1,0)%>
(6665.900)
Note that the second example uses a string, and two is not a number. When a string can be interpreted as a number, you can use that string as a parameter to the function FormatNumber (). If the string cannot be interpreted as a number, an error is returned.
The last example uses all the parameters of the function FormatNumber ():
The first parameter (-6665.8999) specifies the number to be formatted.
The second parameter (3) specifies the number of digits to display after the decimal point.
The third parameter (-1) specifies whether to display a leading 0.
The fourth argument (-1) Specifies whether parentheses are used for negative numbers.
The last argument (0) specifies whether to display the separator character.
Attention
Many VBScript functions use three-state constants. The third, four, and fifth arguments of a function formatnumber () can accept a three-state constant or their value. The three-state constants are listed below:
TristateTrue-1 True
Tristatefalse 0 False
TristateUseDefault-2 using Regional Settings
You can also specify that a particular property of these formats depends on the locale in the Windows Control Panel.

If you need to format percentages, use the function formatpercent ():
<%=formatpercent (%>)
1,200.00%
<%=formatpercent ("a")%>
1,200.00%
This function multiplies its first argument by 100 and appends a percent semicolon to the result. function FormatPercent () can also accept many additional parameters to change the output format.

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.