Created
September 10, 2013 18:08
-
-
Save gscattolin/6513239 to your computer and use it in GitHub Desktop.
String Format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String Format for Double | |
// just two decimal places | |
String.Format("{0:0.00}", 123.4567); // "123.46" | |
String.Format("{0:0.00}", 123.4); // "123.40" | |
String.Format("{0:0.00}", 123.0); // "123.00" | |
// max. two decimal places | |
String.Format("{0:0.##}", 123.4567); // "123.46" | |
String.Format("{0:0.##}", 123.4); // "123.4" | |
String.Format("{0:0.##}", 123.0); // "123" | |
// at least two digits before decimal point | |
String.Format("{0:00.0}", 123.4567); // "123.5" | |
String.Format("{0:00.0}", 23.4567); // "23.5" | |
String.Format("{0:00.0}", 3.4567); // "03.5" | |
String.Format("{0:00.0}", -3.4567); // "-03.5" | |
String.Format("{0:0,0.0}", 12345.67); // "12,345.7" | |
String.Format("{0:0,0}", 12345.67); // "12,346" | |
String.Format("{0:0.0}", 0.0); // "0.0" | |
String.Format("{0:0.#}", 0.0); // "0" | |
String.Format("{0:#.0}", 0.0); // ".0" | |
String.Format("{0:#.#}", 0.0); // "" | |
String.Format("{0,10:0.0}", 123.4567); // " 123.5" | |
String.Format("{0,-10:0.0}", 123.4567); // "123.5 " | |
String.Format("{0,10:0.0}", -123.4567); // " -123.5" | |
String.Format("{0,-10:0.0}", -123.4567); // "-123.5 " | |
String.Format("{0:0.00;minus 0.00;zero}", 123.4567); // "123.46" | |
String.Format("{0:0.00;minus 0.00;zero}", -123.4567); // "minus 123.46" | |
String.Format("{0:0.00;minus 0.00;zero}", 0.0); // "zero" | |
String.Format("{0:my number is 0.0}", 12.3); // "my number is 12.3" | |
String.Format("{0:0aaa.bbb0}", 12.3); // "12aaa.bbb3" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment