473,408 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

CDec() rounding?

djc
I have a sql field (MSDE 2000) of type Decimal. When inserting a value into
the field from an asp.net web form I am using the CDec() function. If I
enter a 2.1 through a 2.4 a 2.00 is entered into the database. If I enter a
2.5 through a 2.9 a 3.00 is entered into the database???? Here is the stored
procedure I'm using and a vb.net code snippet:

-------------------------------------------------------
CREATE PROCEDURE dbo.UpdateHoursEstimate
(@MainID INT, @NewHoursEstimate DECIMAL)

AS

UPDATE tblMain
SET EstimatedHours = @NewHoursEstimate
WHERE MainID = @MainID
GO
---------------------------------------------------

----------------------------------------------------
<snippet>
Dim Param_NewHoursEstimate As New SqlParameter("@NewHoursEstimate",
SqlDbType.Decimal)
Param_NewHoursEstimate.Value = CDec(txtEstimatedHours.Text)
.Parameters.Add(Param_NewHoursEstimate)
</snippet?
----------------------------------------------------

I have entered data directly into the table without issue. So I know the sql
table accepts and stores the numbers I expect. Where is this rounding taking
place?

any info is appreciated. Thanks.
Nov 21 '05 #1
6 8774
djc
I have verified the issue is not with CDec() by checking that value right
before it is assigned to the value of the SqlParameter. So the issue must be
within the stored procedure itself or the parameter object itself. I did
notice one strange thing in the declaration of this SqlParameter object. I
am using ASP Web Matrix which color codes the code for legibility. Just the
word 'decimal' in 'SqlDbType.Decimal' is in blue text? Other items that are
in blue text are elements of the vb.net language itself like IF Then, End
If, Dim, etc... This is probably a big clue to the problem and what I need
to do to fix it... so if Decimal is a keyword or something then how do I
declare this SqlParameter correctly?

anyone?

"djc" <no***@nowhere.com> wrote in message
news:OM*************@TK2MSFTNGP14.phx.gbl...
I have a sql field (MSDE 2000) of type Decimal. When inserting a value into the field from an asp.net web form I am using the CDec() function. If I
enter a 2.1 through a 2.4 a 2.00 is entered into the database. If I enter a 2.5 through a 2.9 a 3.00 is entered into the database???? Here is the stored procedure I'm using and a vb.net code snippet:

-------------------------------------------------------
CREATE PROCEDURE dbo.UpdateHoursEstimate
(@MainID INT, @NewHoursEstimate DECIMAL)

AS

UPDATE tblMain
SET EstimatedHours = @NewHoursEstimate
WHERE MainID = @MainID
GO
---------------------------------------------------

----------------------------------------------------
<snippet>
Dim Param_NewHoursEstimate As New SqlParameter("@NewHoursEstimate",
SqlDbType.Decimal)
Param_NewHoursEstimate.Value = CDec(txtEstimatedHours.Text)
.Parameters.Add(Param_NewHoursEstimate)
</snippet?
----------------------------------------------------

I have entered data directly into the table without issue. So I know the sql table accepts and stores the numbers I expect. Where is this rounding taking place?

any info is appreciated. Thanks.

Nov 21 '05 #2
djc
I have verified the issue is not with CDec() by checking that value right
before it is assigned to the value of the SqlParameter. So the issue must be
within the stored procedure itself or the parameter object itself. I did
notice one strange thing in the declaration of this SqlParameter object. I
am using ASP Web Matrix which color codes the code for legibility. Just the
word 'decimal' in 'SqlDbType.Decimal' is in blue text? Other items that are
in blue text are elements of the vb.net language itself like IF Then, End
If, Dim, etc... This is probably a big clue to the problem and what I need
to do to fix it... so if Decimal is a keyword or something then how do I
declare this SqlParameter correctly?

anyone?

"djc" <no***@nowhere.com> wrote in message
news:OM*************@TK2MSFTNGP14.phx.gbl...
I have a sql field (MSDE 2000) of type Decimal. When inserting a value into the field from an asp.net web form I am using the CDec() function. If I
enter a 2.1 through a 2.4 a 2.00 is entered into the database. If I enter a 2.5 through a 2.9 a 3.00 is entered into the database???? Here is the stored procedure I'm using and a vb.net code snippet:

-------------------------------------------------------
CREATE PROCEDURE dbo.UpdateHoursEstimate
(@MainID INT, @NewHoursEstimate DECIMAL)

AS

UPDATE tblMain
SET EstimatedHours = @NewHoursEstimate
WHERE MainID = @MainID
GO
---------------------------------------------------

----------------------------------------------------
<snippet>
Dim Param_NewHoursEstimate As New SqlParameter("@NewHoursEstimate",
SqlDbType.Decimal)
Param_NewHoursEstimate.Value = CDec(txtEstimatedHours.Text)
.Parameters.Add(Param_NewHoursEstimate)
</snippet?
----------------------------------------------------

I have entered data directly into the table without issue. So I know the sql table accepts and stores the numbers I expect. Where is this rounding taking place?

any info is appreciated. Thanks.

Nov 21 '05 #3
When declaring a decimal, supply the precision and scale parameters (see SQL
Server Books Online for detailed explanation)
The default scale for scale is 0 (ie no digits to right of decimal point)
ie
CREATE PROCEDURE dbo.UpdateHoursEstimate
(
@MainID INT,
@NewHoursEstimate DECIMAL(precision,scale)
)
Stephen

"djc" <no***@nowhere.com> wrote in message
news:OM*************@TK2MSFTNGP14.phx.gbl...
I have a sql field (MSDE 2000) of type Decimal. When inserting a value into
the field from an asp.net web form I am using the CDec() function. If I
enter a 2.1 through a 2.4 a 2.00 is entered into the database. If I enter
a
2.5 through a 2.9 a 3.00 is entered into the database???? Here is the
stored
procedure I'm using and a vb.net code snippet:

-------------------------------------------------------
CREATE PROCEDURE dbo.UpdateHoursEstimate
(@MainID INT, @NewHoursEstimate DECIMAL)

AS

UPDATE tblMain
SET EstimatedHours = @NewHoursEstimate
WHERE MainID = @MainID
GO
---------------------------------------------------

----------------------------------------------------
<snippet>
Dim Param_NewHoursEstimate As New SqlParameter("@NewHoursEstimate",
SqlDbType.Decimal)
Param_NewHoursEstimate.Value = CDec(txtEstimatedHours.Text)
.Parameters.Add(Param_NewHoursEstimate)
</snippet?
----------------------------------------------------

I have entered data directly into the table without issue. So I know the
sql
table accepts and stores the numbers I expect. Where is this rounding
taking
place?

any info is appreciated. Thanks.

Nov 21 '05 #4
When declaring a decimal, supply the precision and scale parameters (see SQL
Server Books Online for detailed explanation)
The default scale for scale is 0 (ie no digits to right of decimal point)
ie
CREATE PROCEDURE dbo.UpdateHoursEstimate
(
@MainID INT,
@NewHoursEstimate DECIMAL(precision,scale)
)
Stephen

"djc" <no***@nowhere.com> wrote in message
news:OM*************@TK2MSFTNGP14.phx.gbl...
I have a sql field (MSDE 2000) of type Decimal. When inserting a value into
the field from an asp.net web form I am using the CDec() function. If I
enter a 2.1 through a 2.4 a 2.00 is entered into the database. If I enter
a
2.5 through a 2.9 a 3.00 is entered into the database???? Here is the
stored
procedure I'm using and a vb.net code snippet:

-------------------------------------------------------
CREATE PROCEDURE dbo.UpdateHoursEstimate
(@MainID INT, @NewHoursEstimate DECIMAL)

AS

UPDATE tblMain
SET EstimatedHours = @NewHoursEstimate
WHERE MainID = @MainID
GO
---------------------------------------------------

----------------------------------------------------
<snippet>
Dim Param_NewHoursEstimate As New SqlParameter("@NewHoursEstimate",
SqlDbType.Decimal)
Param_NewHoursEstimate.Value = CDec(txtEstimatedHours.Text)
.Parameters.Add(Param_NewHoursEstimate)
</snippet?
----------------------------------------------------

I have entered data directly into the table without issue. So I know the
sql
table accepts and stores the numbers I expect. Where is this rounding
taking
place?

any info is appreciated. Thanks.

Nov 21 '05 #5
djc
ah... Thank you! I just posted to the ADO group after realizing my issue was
not with VB thinking it was a more appropriate place for this. But hey,
cool, thanks a lot!

"Stephen Muecke" <st*****@senet.com.au> wrote in message
news:uX**************@TK2MSFTNGP11.phx.gbl...
When declaring a decimal, supply the precision and scale parameters (see SQL Server Books Online for detailed explanation)
The default scale for scale is 0 (ie no digits to right of decimal point)
ie
CREATE PROCEDURE dbo.UpdateHoursEstimate
(
@MainID INT,
@NewHoursEstimate DECIMAL(precision,scale)
)
Stephen

"djc" <no***@nowhere.com> wrote in message
news:OM*************@TK2MSFTNGP14.phx.gbl...
I have a sql field (MSDE 2000) of type Decimal. When inserting a value into the field from an asp.net web form I am using the CDec() function. If I
enter a 2.1 through a 2.4 a 2.00 is entered into the database. If I enter a
2.5 through a 2.9 a 3.00 is entered into the database???? Here is the
stored
procedure I'm using and a vb.net code snippet:

-------------------------------------------------------
CREATE PROCEDURE dbo.UpdateHoursEstimate
(@MainID INT, @NewHoursEstimate DECIMAL)

AS

UPDATE tblMain
SET EstimatedHours = @NewHoursEstimate
WHERE MainID = @MainID
GO
---------------------------------------------------

----------------------------------------------------
<snippet>
Dim Param_NewHoursEstimate As New SqlParameter("@NewHoursEstimate",
SqlDbType.Decimal)
Param_NewHoursEstimate.Value = CDec(txtEstimatedHours.Text)
.Parameters.Add(Param_NewHoursEstimate)
</snippet?
----------------------------------------------------

I have entered data directly into the table without issue. So I know the
sql
table accepts and stores the numbers I expect. Where is this rounding
taking
place?

any info is appreciated. Thanks.


Nov 21 '05 #6
djc
ah... Thank you! I just posted to the ADO group after realizing my issue was
not with VB thinking it was a more appropriate place for this. But hey,
cool, thanks a lot!

"Stephen Muecke" <st*****@senet.com.au> wrote in message
news:uX**************@TK2MSFTNGP11.phx.gbl...
When declaring a decimal, supply the precision and scale parameters (see SQL Server Books Online for detailed explanation)
The default scale for scale is 0 (ie no digits to right of decimal point)
ie
CREATE PROCEDURE dbo.UpdateHoursEstimate
(
@MainID INT,
@NewHoursEstimate DECIMAL(precision,scale)
)
Stephen

"djc" <no***@nowhere.com> wrote in message
news:OM*************@TK2MSFTNGP14.phx.gbl...
I have a sql field (MSDE 2000) of type Decimal. When inserting a value into the field from an asp.net web form I am using the CDec() function. If I
enter a 2.1 through a 2.4 a 2.00 is entered into the database. If I enter a
2.5 through a 2.9 a 3.00 is entered into the database???? Here is the
stored
procedure I'm using and a vb.net code snippet:

-------------------------------------------------------
CREATE PROCEDURE dbo.UpdateHoursEstimate
(@MainID INT, @NewHoursEstimate DECIMAL)

AS

UPDATE tblMain
SET EstimatedHours = @NewHoursEstimate
WHERE MainID = @MainID
GO
---------------------------------------------------

----------------------------------------------------
<snippet>
Dim Param_NewHoursEstimate As New SqlParameter("@NewHoursEstimate",
SqlDbType.Decimal)
Param_NewHoursEstimate.Value = CDec(txtEstimatedHours.Text)
.Parameters.Add(Param_NewHoursEstimate)
</snippet?
----------------------------------------------------

I have entered data directly into the table without issue. So I know the
sql
table accepts and stores the numbers I expect. Where is this rounding
taking
place?

any info is appreciated. Thanks.


Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: spebola | last post by:
I am using vb.net 2003 professional and I get the following results when using the round method: dim Amount as decimal = 180.255 Amount = Amount.Round(Amount, 2) Amount now contains 180.25. ...
0
by: djc | last post by:
I have a sql field (MSDE 2000) of type Decimal. When inserting a value into the field from an asp.net web form I am using the CDec() function. If I enter a 2.1 through a 2.4 a 2.00 is entered into...
8
by: Zorpiedoman | last post by:
Howcome: Dim D as decimal = .5D msgbox d.Round(D, 0) this returns "0" Now when I went to school .5 rounds UP to 1 not DOWN to zero?????!!! Documentation says this, but what the heck are...
11
by: cj | last post by:
Lets assume all calculations are done with decimal data types so things are as precise as possible. When it comes to the final rounding to cut a check to pay dividends for example in VB rounding...
4
by: cj | last post by:
I thought, apparently incorrectly, CDec("") would result in 0D. Unless someone here can tell me something better it seems in reading my report file I'll have to say something like amount =...
7
by: James | last post by:
Can anyone explain the difference between these two conversion functions? Thanks
18
by: jdrott1 | last post by:
i'm trying to round my currency string to end in 9. it's for a pricing application. this is the function i'm using to get the item in currency: FormatCurrency(BoxCost, , , , TriState.True) if...
206
by: md | last post by:
Hi Does any body know, how to round a double value with a specific number of digits after the decimal points? A function like this: RoundMyDouble (double &value, short numberOfPrecisions) ...
20
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.