Results 1 to 7 of 7

Thread: Round decimal to 2 places in datagrid?[RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2002
    Posts
    54

    Round decimal to 2 places in datagrid?[RESOLVED]

    I have a OLEDb(access) that I am using w/ an application. The problem is that when the DataAdapter loads the dataset it looks similar to this : 0.684547643434648. How do I get this to round to 0.68. I've tried changing the data type in the XML schema with no luck. Right now it is setup as a decimal. Any ideas?
    Last edited by Nintendo_Wizard; Jan 16th, 2003 at 12:26 PM.

  2. #2
    Member EagleEye's Avatar
    Join Date
    May 2002
    Location
    South Carolina, USA
    Posts
    43
    in your DataGridColumnStyle under format use :

    VB Code:
    1. #.00


    In case you need to learn about datagrid formatting:

    Walkthrough:

    http://msdn.microsoft.com/library/de...asicPrimer.asp

    Sample App:

    http://msdn.microsoft.com/library/en...ormatting.asp?
    Eagle Eye

    "Programming is easy ... when you are done."

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2002
    Posts
    54
    Thanks for your reply EagleEye! I must not be doing it right, because its not working for me. This is what I tried:
    TableStyles --> DataGridTableStyle --> GridColumnStlye--> DataGrid Column stlye--> format --> #.00. After doinf this the datagrid still displays number as .9895656454343444343. What am I missing? Thanks..
    Last edited by Nintendo_Wizard; Jan 7th, 2003 at 10:49 AM.

  4. #4
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401
    are you using an SQL statement to retrieve the recordset? if so you could use the Format function in the SQL. e.g.:

    Code:
        strSQLStm = "SELECT Format(ColumnName, '#.00') AS NewcolumnName, OtherColumnName01, OtherColumnName02 " & _ 
                    "FROM TableName WHERE ..... ORDER BY ...."
    "The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.

    Windows & Web Developer
    Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
    Sutherland Shire, Sydney Australia
    www.stingrae.com.au
    Developer of Arnold - Gym & Martial Arts Database Management System
    www.gymdatabase.com.au

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2002
    Posts
    54
    Hey stingrae! Thanks for the advice. How would I apply the SQL statement you gave me in the command text of the OleDataAdapter?

  6. #6
    Hyperactive Member stingrae's Avatar
    Join Date
    Apr 2002
    Location
    Sydney
    Posts
    401
    sure:

    here's an example from a project of mine.

    Code:
            lstRate.Items.Clear()
            lstPrice.Items.Clear()
            lstTax.Items.Clear()
            Dim strSQLStm As String
            strSQLStm = "SELECT itm_ID, itm_Name, IIf(IsNull([itr_Name]),'[Not Specified]',[itr_Name]) AS Rate, " & _
                               " Format([itr_Price],'$#,##0.00') AS Price,  Format([itr_Tax],'$#,##0.00') AS Tax " & _
                        "FROM tbl_ItemRate RIGHT JOIN " & _
                                           "(tbl_ItemMaster RIGHT JOIN " & _
                                                           "(tbl_PackageMaster " & _
                                                                     "LEFT JOIN tbl_PackageItems " & _
                                                                            "ON tbl_PackageMaster.pkg_ID = tbl_PackageItems.pki_Package) " & _
                                                                   "ON tbl_ItemMaster.itm_ID = tbl_PackageItems.pki_Item) " & _
                                                  "ON tbl_ItemRate.itr_ID = tbl_PackageItems.pki_Rate " & _
                        "WHERE (tbl_PackageMaster.pkg_ID = " & PkgID & ") " & _
                        "ORDER BY tbl_PackageItems.pki_Order"
            Dim cmdItems As New OleDb.OleDbCommand(strSQLStm, gconDatabase)
            Dim datItems As OleDb.OleDbDataReader
            datItems = cmdItems.ExecuteReader
            Do Until datItems.Read = False
                lstRate.Items.Add(datItems("Rate"))
                lstPrice.Items.Add(datItems("Price"))
                lstTax.Items.Add(datItems("Tax"))
            Loop
            datItems.Close()
    "The passion lives to keep your faith, though all are different, all are great" ... Michael Hutchence 1960-1997.

    Windows & Web Developer
    Specialising in Visual Basic .Net & Client Server Programming & Client/Customer Relations Databases
    Sutherland Shire, Sydney Australia
    www.stingrae.com.au
    Developer of Arnold - Gym & Martial Arts Database Management System
    www.gymdatabase.com.au

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2002
    Posts
    54
    THANKS! Your code works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width