I have this line, where I need to format a field. I did it in different ways and nothing:
lista.ForEach(e => e.Total = string.Format("{0:N}", float.Parse(e.Total)));
and so
lista.ForEach(e => e.Total = string.Format("{0:0.00}", float.Parse(e.Total)));
and more so
lista.ForEach(e => e.Total = string.Format("{0:0,0.00}", float.Parse(e.Total)));
So it comes from the bank: 205,728 and the output should be this: 205,73 and it looks like this: 205,728.00 p>
The complete method
public List<ItensLibDTO> getItensLib(int id)
{
var lista = contexto.ItensLibs
.Where(itens => itens.IdOrcamento == id)
.Select(item => new ItensLibDTO
{
Produto = item.Produto,
Qtde = item.Qtde.ToString(),
Unitario = item.Unitario.ToString(),
Custo = item.Custo.ToString(),
CustoDiario = item.CustoDiario.ToString(),
UltCondicao = item.UltCondicao.ToString(),
Total = item.Total.ToString()
}).ToList();
lista.ForEach(e => e.UltCondicao = new DateTime(1800, 12, 28).AddDays(float.Parse(e.UltCondicao)).ToString("dd/MM/yyyy"));
lista.ForEach(e => e.Total = string.Format("{0:N}", float.Parse(e.Total)));
return lista;
}