Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 21st, 2006, 02:37 PM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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>



 
Old January 5th, 2007, 04:01 PM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old January 5th, 2007, 04:12 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
 
Old January 7th, 2007, 10:46 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks both - working fine - thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Number with 2 decimal places only pallone SQL Server 2000 4 July 3rd, 2007 07:29 AM
Round to 2 decimal places adman JSP Basics 0 June 30th, 2005 07:24 AM
Two decimal places only pallone Javascript How-To 5 February 2nd, 2005 12:35 AM
Set Decimal Places Programatically ritag Excel VBA 2 August 16th, 2004 09:18 AM
output only 2 decimal places Toka1 Javascript How-To 2 February 20th, 2004 11:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.