c# - Emitting a colon via format string in .NET -
Does anyone know how to create a format string in .net so that the resultant string has any colon?
In detail, I have a value, say 200, I need a format as a ratio, that is, "1: 200". That's why I'm building a format string like "1: {0: N0}" that works fine. The problem is that I want to display zero as "0", not "1: 0", so my format string should be like "{0: 1: N0 ;; N0}", but of course it Does not work.
Any thoughts? Thanks!
using the system; Namespace Console Application 67 {Class Program {Static Zero Main () {WriteRatio (4); WriteRatio (0); WriteRatio (-200); Console.ReadLine (); } Private static zero WriteRatio (int i) {Console.WriteLine (string.Format (@ "{0: 1 \: 0; -1 \ 0: 0; 0} \ 0}, i));}}}
returns
1: 4 0 -1: 200
;
format string In the mean, the separator means positive numbers like this; negative number like this; and thus zero 'colon escape with \
is equal to the standard numerical format output as zero, the third \
Required Strictly is not required.)
Comments
Post a Comment