How to correctly apply String.Format

Asked

Viewed 62 times

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));
        } 
       
    }

}

That once loading the page bring the data that exist in the class in decimal form, however the field is bringing so: inserir a descrição da imagem aqui

Only the right I need would be:inserir a descrição da imagem aqui

Obs.

1 - I’m applying the masks on these Textbox in jQuery

Code jQuery:

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 - Fields declared in class and table are decimal

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

Can help me to format properly?

  • How is the application/machine culture configured? Are you sure you want to configure this in the server request?

  • @bigown actually I’m pretty lost in that regard, I don’t know where I can treat it in the best way.

1 answer

1


No entering the client/server side issue,

your problem is just being the signal , where it should be .

Behold:

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

but I’d still do it that way:

txtBonMaster.Text = objBonusVenda.BonMaster.ToString("0.00");
txtBonFilhote.Text = objBonusVenda.BonFilhote.ToString("0.00");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.