1
I have an integer value of 1500 in the monetary value variable and want to send to another value variable like 1500.00 . How to do in c#. I have tried conversions and nothing happens... In the end, the variable Decimal Value must be filled as 1500.00. I made several forms and nothing happens. I don’t know what to do. Part of the routine is this;
string valorreceb = ((registro.Cells["Valor"].Value.ToString()));
valorreceb = valorreceb.ToString().Replace(".", ",");
if (string.IsNullOrEmpty(registro.Cells["Valor"].Value.ToString()) || valorreceb == "0")
{
String valor2 = "0.00";
cepXml.AppendFormat("\t\t<Valor>{0}</Valor>\r\n", valor2);
}
else
{
decimal d = Convert.ToDecimal(valorreceb);
string Valordecimal = Convert.ToString(d);
string sVariavelNova = Valordecimal.Replace(",", ".");
cepXml.AppendFormat("\t\t<Valor>{0}</Valor>\r\n", Valordecimal);
}
I don’t really know how to do it in the technology you’re using, which I don’t even know exactly. But I can almost guarantee you that keep doing conversion,
Replace()
and things like that are the wrong way. You probably have to useCulture
– Maniero
as amazing as it sounds! I did it. the following routine: Cultureinfo _ptbr = Cultureinfo.Createspecificculture("en-BR"); d.Tostring("00.00", _ptbr); string test= string.Format(_ptbr, "{0:00,00}", d);
– Joelias Andrade
I thought I could do it, I didn’t answer because the question didn’t make the context of what you were doing so clear. I could get it wrong. You can post as an answer.
– Maniero