[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2304
  • Last Modified:

GridView - Format Cell To Remove Trailing Zeros From Decimal Value

Hi,

I’m using ASP.NET 2 with VB and SQL Server.  I’m using the GridView control.  The 2nd column on my grid contains decimal values. The GridView displays it as 15.3300000000000000.  How do I format the 2nd column to remove the trailing zeros?  I would like it formatted as 15.33?

My code is as follows:

Private Sub LoadSourceReports()

        sCon = oCon.SqlConString
        Dim Con As SqlConnection = New SqlConnection(sCon)

        sSql = "Select [Source of Reports],[%],Number from vwSourceReports_2"

        Dim da As New SqlClient.SqlDataAdapter(sSql, sCon)
        Dim ds As New DataSet
        ds = New DataSet()
        da.Fill(ds, "vwSourceReports_2")
        Me.grdSourceReports.DataSource = ds
        Me.grdSourceReports.DataBind()

    End Sub

Thanks,
Denise

0
DeniseGoodheart
Asked:
DeniseGoodheart
  • 2
2 Solutions
 
bele04Commented:
Hi,

You can change the dataformatstring property of your 2nd column to "{0:F2}"

more info on dataformatstring:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring(VS.80).aspx

hope it helps
-bele04-
0
 
SKumar_1981Commented:
try this,

in the properties of the grid,
For 2nd column change the dataformatstring property to "{0:F2}"
regards,
skumar
0
 
DeniseGoodheartAuthor Commented:
Hi Skumar,

Thanks for your suggestion.  I tried {0:F2} and it did not work.  Any more suggestions?

Thanks,
Denise

0
 
DeniseGoodheartAuthor Commented:
Hi All,

Both of your answers were very helpful.  After I set the HtmlEncode property of that column to “False", it worked!  

Many Thanks,
Denise
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now