Rounding numeric data

  • Hi,

    I have the following record in my table.

    Cust#       Sal

    A            1000.00

    B            1.43838383838E+1

    C            -12.39393E-1

    How can I round only the last two records?

    help will be appreciated.

     

  • what data type is you Sal column?

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • varchar(25)

    this data is coming to an import table. From there, it is validated and sent to the real table.

    In real table, the data type is money.

  • Wouldn't that round just fine (to 4 digits precision) just be being copied into a money data type?  The negative number becomes -1.2394

  • thanks for your mail. When I DTS it, it should become -1.20 OR -1.30 insread of being skipped.

  • Any scoop on this?

  • Do you mean that you want to round it to the nearest *tenth* instead of the nearest *ten-thousandth*?

  • Yes/

  • Ram,

    Dunno about the others, but I need to know why you want to simply throw away so many decimal places especially since the target datatype (Money) has 4 decimal places inherently available.  Is this, perchance, some form of duration, say, minutes that you want rounded to the nearest 1/10th of a minute?  If not, what is it?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks for your mail.

    I am gettign this data from a remote location where the users might have made the data entry incorrectly. But, still I have to validate this data.

     

    Thx,

    Ram

  • Ok... not the explanation I was looking for but I guess it'll do.

    If you want to round to a single decimal place, then convert it to to something like DECIMAL(19,1) and let the natural rounding take care of the rest.  First, you'll need to convert the char value to FLOAT (scientific notation won't convert to much else) and then convert to a single place decimal number... here's an oversimplified example...

    INSERT INTO yourtable (targetcolumn)

    SELECT CAST(CAST(sourcedata AS FLOAT) AS DECIMAL(19,1))

      FROM yourstagingtable

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks for your time and it worked... Appreciate it..

    -- R

  • You bet.  Thank you for the feedback, Ram.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 13 posts - 1 through 12 (of 12 total)

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