Home > DeveloperSection > Forums > how to round decimal value in Gridview
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    November-20-2014 10:37 PM

 ASP.Net ASP.Net  Gridview 
Ratings:


 1 Reply(s)
 744  View(s)
Rate this:

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>



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    November-20-2014 11:47 PM

Hi Jeet, 

try this:

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


Don't want to miss updates? Please click the below button!

Follow MindStick