Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Last active July 17, 2016 19:15
Show Gist options
  • Save Fhernd/7008b6d54abc34d838e6d29d86d78490 to your computer and use it in GitHub Desktop.
Save Fhernd/7008b6d54abc34d838e6d29d86d78490 to your computer and use it in GitHub Desktop.
Código de ejemplo para cadenas de caracteres personalizadas. [OrtizOL]
// Placeholder numérico: #
Console.WriteLine(12.345.ToString(".##"));
Console.WriteLine(12.345.ToString(".####"));
// Placeholder con cero:
Console.WriteLine(12.345.ToString(".00"));
Console.WriteLine(12.345.ToString(".0000"));
// Separador de grupos: ,
Console.WriteLine(1234.ToString("#,###,###"));
Console.WriteLine(1234.ToString("0,000,000"));
// Multiplicador: ,
Console.WriteLine(1000000.ToString("#,"));
Console.WriteLine(1000000.ToString("#,,"));
// Notación porcentual: ,
Console.WriteLine(0.6.ToString("00%"));
// Notación exponencial:
Console.WriteLine(1234.ToString("0E0"));
Console.WriteLine(1234.ToString("0E+0"));
Console.WriteLine(1234.ToString("0.00E00"));
Console.WriteLine(1234.ToString("0.00e00"));
// Carácter de escape: \
Console.WriteLine(50.ToString(@"\#0"));
// Cadena literal con comillas: 'xx' 'xx'
Console.WriteLine(50.ToString("0 '...'"));
// Separador de sección: ;
Console.WriteLine(15.ToString("#;(#);cero"));
Console.WriteLine((-15).ToString("#;(#);cero"));
Console.WriteLine(0.ToString("#;(#);cero"));
// Cualquier otro carácter:
Console.WriteLine(35.2.ToString("$0 . 00c"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment