Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

format decimals

Tags:

c#

I've found some example code which have this line

string.Format(CultureInfo.InvariantCulture, "{0};{1:f2};{2:f3};",item, someDecimalField, decimalAgain);

What are these {1:f2};{2:f3} and where I can found further info.

Thanks

like image 420
user1765862 Avatar asked Dec 13 '25 10:12

user1765862


1 Answers

Those are standard format strings.

"F" is the fixed point format specifier:

The fixed-point ("F) format specifier converts a number to a string of the form "-ddd.ddd…" where each "d" indicates a digit (0-9). The string starts with a minus sign if the number is negative.

The precision specifier indicates the desired number of decimal places. If the precision specifier is omitted, the current NumberFormatInfoNumberDecimalDigits property supplies the numeric precision.

like image 112
Darin Dimitrov Avatar answered Dec 14 '25 23:12

Darin Dimitrov