Hola. He creado esta función (cuyo nombre es pelín desastroso, y de hecho solicito que me sugerais ideas), porque me pidieron que debia acortar el precio mostrado en el report factura para sólo imprimir dos decimales.
Habra otros modos de hacerlo, pero a mi este me resulta muy útil.
private string AcortarCifra(decimal cifra)
{
string strCifra = Convert.ToString(cifra);
int dondeestalacoma = strCifra.IndexOf(',');
string partedecimal;
string parteentera;
if (dondeestalacoma != -1)
{
if (strCifra.Length > (dondeestalacoma + 2))
{
partedecimal = strCifra.Substring(dondeestalacoma + 1, 2);
parteentera = strCifra.Substring(0, dondeestalacoma);
strCifra = parteentera + "," + partedecimal;
}
}
else
strCifra = strCifra + ",00";
return strCifra;
}