How to properly apply String.Format

0

I have the following event:

protected void Page_Load(object sender, EventArgs e)
{
    this.tituloTela.InnerText = metodos.RetornarNomeMenuTitulo(((System.Web.UI.TemplateControl)(this.Page)).AppRelativeVirtualPath.Remove(0, 2));

    metodos.LiberarAcesso(this.Page, this.GetType(), Form_Cad);
    if (!this.IsPostBack)
    {

        var objBonusVenda = new BonusVenda();
        if (objBonusVenda.ConsultarBonusVenda() > 0)
        {

            txtBonMaster.Text = objBonusVenda.BonMaster.ToString(String.Format("{0:0,0}", value1));
            txtBonFilhote.Text = objBonusVenda.BonFilhote.ToString(String.Format("{0:0,0}", value2));
        } 

    }

}

As soon as you load the page bring up the data that exists in the class as a decimal, however the field is like this:

ExactlywhatIneedis:

Obs.

1 - I'm applying the masks in these Textbox to jQuery

jQuery code:

function aplicarMascaras() {
     $("#<%=txtBonMaster.ClientID%>").maskMoney({ showSymbol: false, decimal: ",", precision: 2, allowZero: false });
         if ($("#<%=txtBonMaster.ClientID%>").val() == "") { $("#<%=txtBonMaster.ClientID%>").val("0,00"); }

     $("#<%=txtBonFilhote.ClientID%>").maskMoney({ showSymbol: false, decimal: ",", precision: 2, allowZero: false });
     if ($("#<%=txtBonFilhote.ClientID%>").val() == "") { $("#<%=txtBonFilhote.ClientID%>").val("0,00"); }
 }

2 - The fields declared in the class and table are as decimal

3 - The variances value1 and value2 are declared at the beginning of the code.

Can you help me with how to format correctly?

    
asked by anonymous 21.06.2017 / 19:45

1 answer

1

Without entering into the client / server side issue,

Your problem is only the , sign where it should be .

See:

txtBonMaster.Text = objBonusVenda.BonMaster.ToString(String.Format("{0:0.0}", value1));
txtBonFilhote.Text = objBonusVenda.BonFilhote.ToString(String.Format("{0:0.0}", value2));

But I would still do it this way:

txtBonMaster.Text = objBonusVenda.BonMaster.ToString("0.00");
txtBonFilhote.Text = objBonusVenda.BonFilhote.ToString("0.00");
    
21.06.2017 / 20:28