1
I have this line, where I need to format a field. I did several 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 like this
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 way out should be this: 205.73 and it’s getting like this: 205.728,00
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;
}
What kind of
item.Unitario
?– Jéf Bueno
@LINQ, double. All monetary values are double. I decided to follow the bank. I thought to play to decimal, but left as is.
– pnet
Okay, remove the
.ToString
within the query. If you want to keep fields likestring
then I suggest you have twice each field then. ThatToString
will confuse everything.– Jéf Bueno
I didn’t understand. He tied me a knot. How so twice?
– pnet
Let’s start from the beginning. Why did you put
ToString
in the numeric fields?– Jéf Bueno
The DTO fields are string and my Model are numerical. I had some problems, which I discussed a lot here on the site and I haven’t gotten any answer. whenever he sent the fields as numeric, except INT and Decimal, gave Cast error. The way found to circumvent this, was to pass the fields of the DTO to string and so I did and so I am able to work. I talked until a Gambi, but that’s what I got.
– pnet
This is a mess, @pnet. I posted the solution
– Jéf Bueno
Have you been able to solve the problem? Did any answers help you with this or missing any details?
– Jéf Bueno
I had marked your answer. Now I could see that you did not mark. But it solved yes the way you had done
– pnet