user662285 user662285 - 3 months ago 13
C# Question

String.format for removing zero after decimal

String.Format("{0:0}",100.00) // Should show as 100 // This works fine
String.Format("{0:0}",0.5) // Should show as 0.5


But above String.Format("{0:0}" does not work.

Answer

If you need 100 and 0.5 respectively, I think the simplest String.Format("{0}", myDouble ) or even myDouble.ToString() could work.

Comments