Pregunta

int a = 10000000;
a.ToString();

¿Cómo hago la salida?

  

10000000

¿Fue útil?

Solución

Trate N0 por ninguna parte decimal:

string formatted = a.ToString("N0"); // 10,000,000

Otros consejos

También se puede hacer String.Format:

int x = 100000;
string y = string.Empty;
y = string.Format("{0:#,##0.##}", x); 
//Will output: 100,000

Si usted tiene decimal, el mismo código dará salida a 2 decimales:

double x = 100000.2333;
string y = string.Empty;
y = string.Format("{0:#,##0.##}", x); 
//Will output: 100,000.23

Para hacer uso de la coma decimal en vez esto:

double x = 100000.2333;
string y = string.Empty;
y = string.Format(System.Globalization.CultureInfo.GetCultureInfo("de-DE"), "{0:#,##0.##}", x);

Una opción más simple String.Format:

int a = 10000000;
String.Format("{0:n0}", a); //10,000,000

a.tostring ( "00000000")

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top