0

I am trying to round the result of my code to 2 decimal places, but ROUND isn't working. Any help? Thanks!

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
     SelectCommand="SELECT [Id], [attempts], [total], (round(attempts / total,(2))) AS [Percentage] FROM [Game]">
</asp:SqlDataSource>
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Here is a [useful link](http://stackoverflow.com/questions/441600/write-a-number-with-two-decimal-places-sql-server) – शेखर Nov 30 '13 at 04:38

2 Answers2

0

I bet you could use

CAST(ROUND(attempts/total,2) as DECIMAL(12,2))

OR

attempts/CAST(total as DECIMAL(12,2))

OR

CAST(attempts AS DECIMAL(12,2))/total
Jeroen Vannevel
  • 43,651
  • 22
  • 107
  • 170
Ross Bush
  • 14,648
  • 2
  • 32
  • 55
0

try this " SelectCommand="SELECT [Id], [attempts], [total], round((attempts / total),2) AS [Percentage] FROM [Game]">

UPDATE:

Have you tried:

SELECT Cast( 2.555 as decimal(53,2))

This would return 2.55 . Is that what you want?