SQL Server Performance

Want only 2 digits

Discussion in 'General Developer Questions' started by georgedamien, Nov 2, 2006.

  1. georgedamien New Member


    Wanted to know if there is any mathematical function which can return just first two digits of a numeric value without rounding it.

    I have used to Round function but it rounds it, want some other function which does not do that.

    select round('3045.4556',2)

    Output
    ------
    3045.46

    I want output as 3045.45


  2. Adriaan New Member

    DECLARE @Test DECIMAL(8,4)
    SET @Test = 3045.4556

    SELECT LEFT(@Test,2)
  3. Adriaan New Member

    Note that if the value is negative, it returns the "-" character and the first digit.

    For values between 0 and 10, it returns the first digit and the "." character.
  4. FrankKalis Moderator

    What about


    SELECT CAST(@test * 100 AS INT) * 1.0 /100

    Works regardless of the sign.
    --
    Frank Kalis
    Moderator
    Microsoft SQL Server MVP
    Webmaster:http://www.insidesql.de

Share This Page