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
  • 159,224
  • 26
  • 237
  • 393
  • 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
  • 42,521
  • 22
  • 100
  • 163
Ross Bush
  • 13,809
  • 2
  • 33
  • 52
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?