3
How to convert the result of a multiplication into a string
to display as Real?
The value of bol.ValorBoleto
is loaded just before.
To data Annotation: [DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:c}")]
doesn’t work.
I tried several ways and I couldn’t.
My code is like this:
[Display(Name = "IRPJ")]
[ReadOnly(true)]
[DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:c}")]
public string IRPJ { get; set; }
public BoletoBancario GerarBoletoBradesco(BoletoModel bol, string txtIrpj)
{
decimal irpj;
irpj = Convert.ToDecimal(txtIrpj);
bol.IRPJ = "IRPJ " + irpj + "%" + " - " + Convert.ToString(bol.ValorBoleto * irpj);
Instrucao objInst3 = new Instrucao(237);
objInst3.Descricao = bol.IRPJ;
}
This code does not make sense, is there an algorithm within the class and outside of methods? Put something that works for us to see how it is. You’re picking up a variable
irpj
that appeared out of nowhere. You’re trying to apply a number formatting on something that is composed of words. That’s the same intention?– Maniero
@bigown, not only is within a class the property, I put everything together to see where I am using. This variable irpj is coming as parameter.
– AndreeH
The way it is, it’s loose in the class, it changes to see how it really did. This code does not even compile.
– Maniero
@bigown, I changed a little, see if you can understand. I need to display the result of this multiplication inside this string in real format.
– AndreeH
Now it is more understandable. But what is the problem? You can make this parameter
txtIrpj
be a number? The property can beDecimal
? It makes no sense for you to format astring
.– Maniero
So I need to display type like "IRPJ 3% - 15.30". This I will display in a billet. txtIrpj is an input value.
– AndreeH
And what’s the problem that’s happening?
– Maniero
It is not converting, it is showing type 689,2210. In the case, in excel this value is R$6,89
– AndreeH