Showing posts with label price. Show all posts
Showing posts with label price. Show all posts

Friday, March 9, 2012

Decimal value is getting rounded

I am writing a simple shopping cart app and the price field is being rounded when inserted into the database.
There is a textbox for the user to enter the price. A stored procedure is used to insert the line item info to the data base table. The field in the table is formatted as datatype decimal. Below is the stored procedure and the code that adds the value to the parameter. Any suggestions on where I am going wrong?
<Code>
CREATE PROCEDURE [sp_insert_CartDetail]
(
@.ReferenceNum [int],
@.Item [varchar](26),
@.Desc1 [varchar](27),
@.Desc2 [varchar](20),
@.Desc3 [varchar](30),
@.Desc4 [varchar](30),
@.Note [text],
@.Quantity [int],
@.DateOrdered [datetime],
@.SalesPrice [decimal],
@.DistCost [decimal],
@.SalesTaxable [smallint],
@.RequiredDate [datetime],
@.User1 [varchar](12),
@.User2 [varchar](12),
@.User3 [varchar](12),
@.User4 [varchar](12),
@.User5 [varchar](12),
@.User6 [varchar](12))

AS INSERT INTO [ToolCrib].[dbo].[CartDetail]
(
[ReferenceNum],
[Item],
[Desc1],
[Desc2],
[Desc3],
[Desc4],
[Note],
[Quantity],
[DateOrdered],
[SalesPrice],
[DistCost],
[SalesTaxable],
[RequiredDate],
[User1],
[User2],
[User3],
[User4],
[User5],
[User6])

VALUES
(
@.ReferenceNum,
@.Item,
@.Desc1,
@.Desc2,
@.Desc3,
@.Desc4,
@.Note,
@.Quantity,
@.DateOrdered,
@.SalesPrice,
@.DistCost,
@.SalesTaxable,
@.RequiredDate,
@.User1,
@.User2,
@.User3,
@.User4,
@.User5,
@.User6)
SqlCmdInsetCartDetail.Parameters("@.SalesPrice").Value =CType(txtCost.Text,Decimal)

</code>

Does the table field have precision and scale set for the decimal type? You'd want to set them also for decimal type parameters.|||db table has precision of 18 and scale of 0. What should it be set to if I want decimal to 4 places. Is decimal the correct data type for this situation?
Thanks,
Danny|||Try this link for code to set the precision and scale in .NET. Hope this helps.
http://support.microsoft.com/?kbid=892406|||I have set the scale to 4 on both the data table and the parameters... No change
Caddre, I don't think that pertains to my situation. 1 - I am running this on MSSQL7. 2-I am not returning a value from the sproc.
|||In SQL Server 7.0 change the data type to Numeric it is more stable in SQL Server 7.0 than Decimal because I remember when Money was rounding to less than one dollar in 1999 the only fix was with Numeric. And set the precision and scale, why I think it comes from TDS(tabular data stream) 7.0. Hope this helps.

Decimal Separator with Comma... is Possible?

In Sql Server Express

I need use in field MONEY

"update product set price='1,23' where cod='001'"

i don′t use

"update product set price='1.23' where cod='001'"

hi,

with all kind of datatypes supporting fixed or non fixed decimal values you have to use the "." as decimal separator... so you have to code

UPDATE ... SET price = 1.23 WHERE...

and this without the " quote for the value...

regards

Decimal Separator in SQL Server with Comma... is possible?

In Brazil decimal separator=comma

SQL SERVER

LANGUAGE=BRAZILIAN OR PORTUGUESE

PRICE=MONEY

"UPDATE PRO SET PRICE='1,11' WHERE COD='0001'"

PRICE=111.00

all aplications use comma... impossible alter all!

Programmatically in SQL you will need to use a dot insted of a comma but the data can be displayed in the front using a comma provided you have the correct regional settings on the front end.