string formatting - Is there a C# format specifier that will omit the leading zero unless the value is zero? -


in other words, want 0.123 show ".123", 0 should show "0". best i've got is

string.format("{0:.###}", n) 

which gives ".123" 0.123, "" (the empty string) 0.

if use ; separator, can specify formats positive, negative, , 0 values. string.format("{0:.###;-.###;0}", n) display '0' when n==0 , leave off leading 0 positive , negative values. check msdn reference here.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -