Using FormatNumber

Results 1 to 2 of 2

Thread: Using FormatNumber

  1. #1
    Join Date
    Dec 1969

    Default Using FormatNumber

    The following code adds a column named TOTAL at the end of the DataGrid & displays the total of each of the rows:<BR><BR>Dim curRows() As DataRow=dTable.Select(Nothing,Nothing,DataViewRowS tate.CurrentRows)<BR>dTable.Columns.Add("TOTAL",Sy stem.Type.GetType("System.Decimal"))<BR>dGrid.Item Style.HorizontalAlign=3<BR> <BR>For Each dRow In curRows<BR>iRowTotal=0<BR>For j=2 To dTable.Columns.Count-1<BR>If(dRow(j) Is DBNull.Value) Then<BR>dRow(j)="0.00"<BR>Else<BR>iRowTotal=iRowTo tal+dRow(j)<BR>End If<BR>Next<BR><BR>If(iRowTotal=0) Then<BR>dRow("TOTAL")="0.00"<BR>Else<BR>dRow("TOTA L")=FormatNumber(iRowTotal,2)<BR>End If<BR>Next<BR><BR>Now I want that the TOTAL which comes to zero should be displayed as 0.00 & not as 0. That&#039;s the reason why I have included a second If.....Else condition in the For....Next loop but still the total gets displayed as 0 & not as 0.00. I also tried using FormatNumber<BR><BR>If(iRowTotal=0) Then<BR>dRow("TOTAL")=FormatNumber(0,2)<BR>....... ..........<BR><BR>but this also doesn&#039;t solve my problem. How do I display the total as 0.00 & not as 0 if the sum of the rows equals zero?<BR><BR>Thanks,<BR><BR>Arpan

  2. #2
    Join Date
    Dec 1969

    Default The field type for..

    .. your dataset/datareader is a numeric type. Numeric types do not include preceding/trailing zeros -- even if you put data that contains them.<BR><BR>You need to actually do the FormatNumber when you DISPLAY the particular data from that field.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts