c# - Changing a decimal format -


i have code:

using (streamwriter writer = new streamwriter("c:\\users\\hp8200\\desktop\\teste.txt")) {                 string numcont = _transaction.partyfederaltaxid;     double numenc = _transaction.billtopartyid;     double numfatura = _transaction.transdocnumber;     datetime data = _transaction.createdate;     double valor = _transaction.totalamount;     short zona = transaction.zone.zoneid;     //ean mal     string ean = transaction.atdoccodeid;     double iva = 23;     //preçoantesdisc mal     double precoantesdisc = _transaction.totalpaymentdiscountamount;     double preconet = transaction.details.totaladvancementnetamount;     double quantidade = transaction.details.count;     double bonus = _transaction.totalpaymentdiscountamount;                  writer.writeline($"{numcont};{numenc};{numfatura};{data.tostring("dd/mm/yyyy")};{valor};{zona}{environment.newline}{ean}{iva};{precoantesdisc};{preconet};{quantidade};{bonus}"); } messagebox.show("saved"); 

and variable valor separating decimal number "," , need "." there way can it?

the variable valor of type double, doesn't use decimal separator, formatted strings have. interpolated string converts , uses current culture default. can use:

string valorstr = valor.tostring(cultureinfo.invariantculture); string line = $"{numcont};{numenc};{numfatura};{data.tostring("dd/mm/yyyy")};{valorstr};{zona}{environment.newline}{ean}{iva};{precoantesdisc};{preconet};{quantidade};{bonus}"; writer.writeline(line); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -