p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   Display Decimal Places (http://p2p.wrox.com/showthread.php?t=51841)

rsm42 December 21st, 2006 02:37 PM

Display Decimal Places
 
Hi,

Can someone assist with a query in asp.net 1.1, vb2003 using access databases. When I display my product list in a datagrid I want the sale price to be displayed e.g. 530.00. Instead the display is shown as 530.

Now the format of the saleprice in the database is set to currency with two decimal places. The only way it seems to display as if the value is other than zeroes at the end e.g. 530.99.

Here's some sample code - any ideas ? Also how about also adding in the pound sign as well i.e. £530.00?

<%@ Page Language="VB" %>
<script runat="server">

        Sub Page_Load
            DataGrid1.DataSource = ShowItems()
            DataGrid1.DataBind()
        End Sub
    '
        Dim curSalePrice As Decimal

        Function ShowItems() As System.Data.IDataReader
            Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=F:\db\nwguitars.mdb"
            Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )

            Dim queryString As String = "SELECT [tblProducts].[intProductID], [tblProducts].[strProductName], [tblProducts"& _
    "].[curSalePrice], [tblProducts].[intQuantityInStock] FROM [tblProducts]"
            Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection

            dbConnection.Open
            Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

            Return dataReader
        End Function

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
           </form>
</body>
</html>




danastasio January 5th, 2007 04:01 PM

I'm pretty new to the ASP world, but found that using
<% response.write FormatNumber(rs("Overall_Rating"),2,-1) %>
will output my data from field "Overall_Rating" using connection 'rs' with the original formatting intact. The data is in a decimal (18,2) field in the SQL database.
I get '4.00' now, versus the '4' I was getting when I simply used
<% response.write rs("Overall_Rating") %>.
Hope this helps.


dparsons January 5th, 2007 04:12 PM

String.Format("{0:c}", [string value]) will produce a string formatted currency (relative to the servers localization settings).

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature

rsm42 January 7th, 2007 10:46 AM

Thanks both - working fine - thanks



All times are GMT -4. The time now is 06:25 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.