truncate decimal places Sql Query

  • Can you plz tell me how to truncate zeros after decimal

    the case is like this

    round(992.55,0)

    result =993.00

    round(993.888)

    result = 994.000

    I dont want to pass decimal spaces,if i want to use 'right' i dont know how many decimal places are going to be.

    And also the value 992.55 is in @amount

    can we use round(@amount,0) ?

    Thanks fror ur help

  • It is not very clear what you want. Can you give us examples that show your data, what you are currently getting and then what you actually want?

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • Not the best solution.. but you can always cast as an int data type if you don't need the precision of a decimal.

    declare @d as decimal(9,3)

    set @d = 339.55

    select CAST(ROUND(@d, 0) AS INT)

  • Are you interested in truncating, or rounding off?

    What are you planning to do with the result? If you're going to display, or pass, it as a whole number, the you may find that some trailing zeroes will will be added to the value. If you're going to convert to a text type (varchar, char, ...) then the number should stay unchanged.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply