Recently I started learning C #, now I came across an incomprehensible mini-topic. I reread it 20 times, whether I want to sleep, or so stupid. But I do not understand anything. MB who can briefly explain, or throw off the article in a more understandable language.
A quote from Schildt’s textbook:
But the main purpose of format specifiers is to control the appearance of the output data. Most often the following types of data are subject to formatting: floating point and decimal. The easiest way to specify a data format is to describe a template that will be used in the
WriteLine()method. For this, a sample of the required format is indicated with the help of the symbols #, denoting digits of numbers. In addition, you can specify a decimal point and commas separating digits.Below is an example of a more appropriate output of the result of dividing 10 by 3.
Console.WriteLine("Деление 10/3 дает: (0:#.##)", 10.0/3.0);Execution of this operator leads to the following result.
Деление 10/3 дает: 3.33In this example, the pattern #. ## tells the WriteLine () method to display two decimal places in the fractional part of a number. It should, however, be borne in mind that the
WriteLine()method can display as many digits to the left of the decimal point as needed to correctly interpret the displayed value.Consider another example. Operator
Console.WriteLine("{0:###,###.##}", 123456.56);gives the following result.
123,456.56"
I did not understand how, when, why, and why the "#" is used
#- replaces the number in the definition of the number format - rdorn