Results 1 to 7 of 7
  1. #1
    Join Date
    May 2006
    Location
    Melbourne
    Posts
    6

    Unanswered: How to specify length of decimal that is displayed

    Hi,

    What I mean is:

    I have a decimal(19,10) variable called @value and it has the value 66.6666666666

    I can round it using ROUND(@value, 0) and the result is 67.000000000

    But what I really want is to get rid of all the zero's and the decimal point so that I end up with just 67

    Thanks in advance,

    Ian.

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi

    You could cast it to an integer value:
    Code:
    DECLARE @p AS DECIMAL(19,10) 
    SELECT @p = 66.6666666666
    SELECT CAST(ROUND(@p, 0) AS Int)
    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    May 2006
    Location
    Melbourne
    Posts
    6
    Thanks (I was thinking about decimals too much and didn't think of that - DOH!).

    How would I do it if I wanted to display: 66.7 (ie 66.6666666666 rounded to 1 decimal place?)

    Cheers,

    Ian.

  4. #4
    Join Date
    Jun 2004
    Posts
    50
    Hi,
    Could you cast it as a char(4) for display purposes? After rounding of course...
    Monk
    The person who confesses ignorance shows it once; the person who conceals it shows it many times.

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd use:
    Code:
    DECLARE @p AS DECIMAL(19,10) 
    SELECT @p = 200.0 / 3
    SELECT CAST(@p AS DECIMAL(19, 1))
    -PatP

  6. #6
    Join Date
    May 2006
    Location
    Melbourne
    Posts
    6
    Doh - never thought of that. Nice one!

    Ian.

  7. #7
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Some days I do Ok. You should see me when I'm awake and fed too... I'm lots less crabby, and more creative!

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •