Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases 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 September 7th, 2006, 11:36 AM
Registered User
 
Join Date: Sep 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default datagridview currency format rounds off cents

DataGridView is bound to the SQL dataset.
The values in the SQL are decimal(18,2).
The format for the columns in the datagridview
are set to C2.
But....
   a value 77.59 displays in the grid as 78.00
   a value 44.49 displays in the grid as 44.00
The cents are rounding to whole dollars.

I also tried using an N2 format and $#,##0.00
They all gave the same results: rounding off the cents
to whole dollars.

This is not a good thing in a banking application.
:(

 
Old September 8th, 2006, 09:51 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Somewhere in your path for the data between the DB and the screen the values are being held as integers.
(You probably already know that.)

I would investigate the logic, the scheme, the philosophy of each link in the chain. For instance, when data are imported into Access from Oracle, the field types are often misrepresented (number fields become text fields, eg).
There might be some interface (DB to network, network to datagrid, whatever) that does not understand the data type, and so is "punting," causing a rounding to be needed.

Not a very specific post, I know. Sorry about that. It's hard to formulate a guess without more specifics, but I hope this nonetheless helps.
 
Old September 12th, 2006, 11:24 AM
Registered User
 
Join Date: Sep 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank You Brian,
You are right about the chain of field definitions. I was looking for it, just could not find it.
The datagrid was set up and bound to my database when the database definition for these numeric fields was integer. I changed the database definition of the fields to be decimal(18,2) and reloaded the data into the database. What I did not know was that the DataTableAdapter? did not get the updated numeric field definitions. It was stuck on the old format. I did not know.

I finally gave up and started over with a new project and the rounding problem disappeared. Then I discovered the editor? that let me change the numeric definitions in the DataTableAdapter? to decimal. Oh happy day!!!!!
Now it works as it should. Why are these tools so darn obscure. I spent weeks looking for a way to edit those field definitions.

Thanks again,

TomH





Similar Threads
Thread Thread Starter Forum Replies Last Post
Currency Format kdkcchoco ASP.NET 1.0 and 1.1 Professional 1 March 29th, 2007 08:13 AM
Currency Format heerajee Pro PHP 2 June 5th, 2006 02:24 AM
format currency civa Access 3 December 16th, 2005 03:50 AM
Display currency amounts, including cents. danielh Javascript How-To 1 January 19th, 2004 06:57 PM





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