Is there a C# equivalent of C++’s stream manipulators?
Eg
int decimalPlaces = 2;
double pi = 3.14159;
cout.precision(decimalPlaces);
cout << pi;
It feels weird having to format a number to a string in order to format a number to a string.
Eg
int decimalPlaces = 2;
double pi = 3.14159;
string format = "N" + decimalPlaces.ToString();
pi.ToString(format);
It that just how it’s done in C#, or did I miss something?
I would shrink it slightly:
Also, you don’t have to format the number before printing it. The printing facilities will accept formatting constructs too.