Decimal Problem

Hey

I'm currently creating a shopping cart, and i'm having a problem with the data transfered to the SQL Database.

Currently writing a C#;

The problem is when i multiply a Decimal by a Int the decimal automatically rounds up, I've set the datatype decimal(6,2),

eg Decimal linetotal = productPrice * Quantity, "52.63 * 2 = 105.26".

I know that 'linetotal' = "105.26", because i'm using the breakpoint in the debug mode, but when i send this total to the database it automatically rounds up to "105.00".

Anyone have any ideas

Thanks Rich




Answer this question

Decimal Problem

  • William Bartholomew

    ok the store procedure im using is:

    ALTER PROCEDURE dbo.UpdateCartItems

    (@CartUID int,@ProductID int,@Quanty int,@Linetotal decimal)

    AS

    IF @Quanty != 0

    UPDATE Cart

    SET Quanty = @Quanty, Linetotal = @Linetotal WHERE ProductID = @ProductID AND CartUID = @CartUID;



  • Giritharan

    can you post your Stored Procedure (if you're using it to update your data)


  • biscuithead

    Thank you so much

  • Frank Miller

    try declaring your @Linetotal with precision & scale, e.g.,
       
        @Linetotal decimal(10, 2)

    check your Linetotal column coz it would be good to have your @Linetotal parameter to be declared as the actual table column's definition.


  • Decimal Problem