Picture Numeric Format Strings (I can hardly explain to everyone)

Source: Internet
Author: User
Tags numeric numeric value
http://msdn.microsoft.com/library/dotnet/cpguide/cpconpicturenumericformatstrings.htm (direct connection URL)
If the built-in formatting strings does not provide the type of formatting your require, you can use the picture format Strings T o Create custom string output. Picture format strings contain a number of format characters this arrange the output of the format method in almost any WA Y imaginable.

The picture number format definitions are described a using placeholder strings that identify the minimum and maximum number of Digits used, the placement or appearance of the negative sign, and the appearance of any other text within the number.

The following table lists the picture formatting characters.


Format character Description Description
0 Display Zero Placeholder Results in a non-significant zero if a number has fewer digits than there are zeros in the form At.
# Display Digit placeholder replaces the ' # ' symbol with only significant digits.
. Decimal point displays a "." character.
, Group Separator
Multiplier
Separates number groups; For example, "1,000".
% Percent notation displays a "%" character.
E+0
E-0

E+0

e-0
Exponent notation Formats The output of Exponent notation.
\ Literal character Used with traditional formatting sequences like "\ n" (newline).
' ABC '
"ABC"
Literal string displays any string within quotes or apostrophes literally.
; Section separator specifies different output if the numeric value to be formatted, positive, or zero.


The following code is a example of the picture number formatting.

[C #]
Double MyDouble = 12.345;

MyDouble. Format ("000.##", null);
Returns the string "012.35"

Double MyDouble = 5.14129
Int32 MyInt = 42

Mydouble.format ("0###.##", NULL)
Results in "0005.14"

Mydouble.format ("%#.##", NULL)
Results in "%514.13"

Myint.format ("My number = #", null)
Results in ' My number = 42 '

Myint.format ("My Number \n= #", NULL)
Results in ' My number
= 42 "
Picture formatting strings can is broken into three sections. If only one of the defined, all numbers'll be formatted as specified. If two sections are defined, the the ' a ' is applied to positive and zero values while the second section'll b E applied to negative numbers. If three sections are defined, the I applies to positive values, the second applies to negative values, and the third Applies to values of zero. For example:

[C #]
int myposint = Mynegint = -42, myzeroint = 0;

Myposint.format ("Positive number = #; Negative number = #; Zero Value = # ", null)

Results in "Positive number = 42"

Mynegint.format ("Positive number = #; Negative number = #; Zero Value = # ", null)

Results in "Negative number =-42"

Myzeroint.format ("Positive number = #; Negative number = #; Zero Value = # ", null)

Results in "Zero Value = 0"


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.