Results 1 to 3 of 3

Thread: [RESOLVED] rounding values

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    97

    Resolved [RESOLVED] rounding values

    Hi Friends

    I've a datatable that developed by my colleague and filled at HTML table (old stayle programming)

    HTML Code:
    <tr>
        <th>City1</th>
        <td><%=string.Format("{0:0}", dtHour.Compute("max(field1)", string.Empty))%></td>
        <td><%=string.Format("{0:0}", dtHour.Compute("min(field1)", string.Empty))%></td>
        <td><%=dtHour.Compute("round(avg(field1),0)", string.Empty)%></td>
        <td><%=dtHour.Compute("sum(field1)", string.Empty)%></td>
     </tr>
    but the value which I get is decimal, I'm trying to round it but dose not work and getting the following error:
    Name:  Error.png
Views: 186
Size:  35.3 KB

    please can anyone help to solve that error and rounding decimal value?

    Regards

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: rounding values

    You can't just make up syntax. Have you read the documentation for the DataTable.Compute method to see what it supports? Presumably not, or you wouldn't have tried to use that in the first place. There is no such function so you can't use it. You can use Compute to calculate the average and then use Math.Round or Decimal.Round to round the result.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    97

    Re: rounding values

    Thank you so much for your quick response

    I've found a simple solution for that issue as follow:

    <tr>
    <th>City1</th>
    <td><%=string.Format("{0:0}", dtHour.Compute("max(field1)", string.Empty))%></td>
    <td><%=string.Format("{0:0}", dtHour.Compute("min(field1)", string.Empty))%></td>
    <td><%=string.Format("{0:0}", dtHour.Compute("avg(field1)", string.Empty))%></td>
    <td><%=string.Format("{0:0}", dtHour.Compute("sum(field1)", string.Empty))%></td>
    </tr>

Posting Permissions

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



Click Here to Expand Forum to Full Width