Skip to content

Limiting decimals

George Laing

Asked Nov 29, 2008, 1:40 PM EST2 answers
Share
LinkedInX

Hi

 I have a numeric column on a datagrid that I am putting into a textbox, The problem is that the value has 4 decimal places and I want to show no decimals. I am not sure though how to convert it to a decimal. pPrem_Optimized in the grid has 4 decimals I want it to show in the textbox with none. Here is the line does anyone know how to limit it to no decimals?

prem_OptimizedTextBox.Text = Grid_Property.Rows[e.RowIndex].Cells["pPrem_Optimized"].Value.ToString();

Thanks

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    +1
    if you want to display decimal in your text content then use

    String.Format( "{0:D}", yourVariable);
    +1
  • +1
    Hope this example will work for you..

    Label1.Text = "12.534";
    Label1.Text = Math.Round(Convert.ToDecimal(Label1.Text),0).ToString();
    +1