Formatted output of numbers

Source: Internet
Author: User

The Format function:

There are 2 parameters:

Parameter 1: The number to be formatted;

Parameter 2: Formatting strings

Example: x=1234.4367

#保留小数点后2位

#输出: "1234.44"

Format (x, ' 0.2f ')

#保留小数点后1位, and the number is right-aligned within a 12-character-length area, leaving space on the left

#输出: "1234.4"

Format (x, ' 12.1f ')

#保留小数点后2位, and the number is left-aligned within 12-character-length areas, followed by 12

#输出: "1234.44 12"

Print (Format (x, ' <12.2f '), 12)

#保留小数点后1位, and in the middle of a 12-character length interval, 0

#输出: "0001234.6000"

Print (Format (x, ' 0^12.1f '))

#加上千分位逗号, keep 2 digits after the decimal point

#输出: "1,234.44"

Format (x, ',. 2f ')

#科学计数法

#输出: "1.234437e+03"

Format (x, ' E ')

#科学计数法, Output 2 decimal places

#输出: "1.23e+03"

Format (x, ' 0.2e ')

Formatted output of numbers

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.