none
How to prevent decimal rounding

    Question

  • Hi everyone,

    I have a decimal column of (18,2) and when I enter in a value of say, 74.6,  it is rounding the value to 75.00.  Is there a way to prevent the value from rounding?


    Thanks!

    Flear

    Saturday, April 03, 2010 3:23 PM

Answers

  • Hey guys,

    Thanks for your reply! After proving your examples were working; I went back to see what I was doing.  My table had it declared decimal(18,2) but my stored procedure had the parameter has decimal(18,0)  which was causing it to round!


    Thanks for your help! It lead me to my type-o!


    Thanks,

    Flea

    • Marked as answer by Flea_ Saturday, April 03, 2010 4:36 PM
    Saturday, April 03, 2010 4:36 PM

All replies

  • I cannot reproduce it. Can you post the T-SQL script?

    -- SQL Server 2008 code
    DECLARE @DEC DECIMAL(18,2) = 74.6
    SELECT @DEC
    -- 74.60

    Kalman Toth, SQL Server & Business Intelligence Training; SQL 2008 GRAND SLAM
    Saturday, April 03, 2010 3:54 PM
  • How do you insert the value and how to you retrieve it? The value should not round:

    CREATE TABLE Foo (keycol INT NOT NULL PRIMARY KEY, x DECIMAL(18, 2));
    
    INSERT INTO Foo VALUES(1, 74.6);
    
    SELECT x
    FROM Foo;
    
    /*
    
    x
    ---------
    74.60
    
    */

    Plamen Ratchev
    Saturday, April 03, 2010 3:55 PM
  • Hey guys,

    Thanks for your reply! After proving your examples were working; I went back to see what I was doing.  My table had it declared decimal(18,2) but my stored procedure had the parameter has decimal(18,0)  which was causing it to round!


    Thanks for your help! It lead me to my type-o!


    Thanks,

    Flea

    • Marked as answer by Flea_ Saturday, April 03, 2010 4:36 PM
    Saturday, April 03, 2010 4:36 PM