can i "%.1f" in C#?
-
In my aged c code, there is tons of "%.1f" in source. How can i transfer it to c#? i read the document of Console.Write. the format is describe by {a,b:s}. How can i get the same result as c format string like "%.1f"?
Are you asking how you can use "%.1f" in C# or for the format string that produces an equivilant to "%.1f"? James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971
-
In my aged c code, there is tons of "%.1f" in source. How can i transfer it to c#? i read the document of Console.Write. the format is describe by {a,b:s}. How can i get the same result as c format string like "%.1f"?
You can use the Math.Round static function or the String.Format method (called implicitly below). double d = 136.7835; Console.WriteLine(Math.Round(d, 1)); Console.WriteLine("{0:.#}", d); Both of these result in 136.8 which is what the C/C++ format specifier %.1f would provide. Cheers, Tom Archer Author, Inside C#
-
In my aged c code, there is tons of "%.1f" in source. How can i transfer it to c#? i read the document of Console.Write. the format is describe by {a,b:s}. How can i get the same result as c format string like "%.1f"?