Split integer valuefrom decimal valye

  • Hi All,

    I want to split integer part from decimal value

    e.g. i have a no is 12456324.254 and i want to the output is 12456324

    Note: We can't use convert function

  • Function floor() does not work? :unsure:

  • Thanks,

    It is working

  • or, use

    ROUND(YourValue, 1)

    (revised) I'm sorry... I meant ROUND(YourValue, 0, 1)

    I apologize for my lack of proof-reading.

    The non-zero 2nd parameter truncates the value, without changing the datatype.

  • indraprakash (7/7/2008)


    Note: We can't use convert function

    The ROUND function with the truncate option is definately the way to go... but why is it that you can't use the CONVERT function?

    --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)

  • Hi,

    round function not gives proper output

    floor is right.

  • indraprakash (7/8/2008)


    Hi,

    round function not gives proper output

    floor is right.

    Ummmm.... why do you think that? Using the optional 3rd parameter of ROUND makes it behave like FLOOR but with more control, if you need 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)

  • I'm sorry... I meant ROUND(YourValue, 0, 1)

    I apologize for my lack of proof-reading.

  • No problem and thanks for the feedback, Phil... I've made similar mistakes... just wanted to be sure...:)

    --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)

  • What if i want the other value not the floor value ...........

    i mean if its 1234.4321

    i want 4321 (values after the decimal place...)?

    Cheers,

    Chandra

  • i know i can do the floor() on a decimal number and then store that to a variable and subtract it from the original number

    example

    @a = 2.75

    @b-2 = floor(2.75)

    @C = @a - @b-2 (this gives me 0.75)

    but is there a function that does this in SQL Server

    Cheers,

    Chandra

  • i know i can do the floor() on a decimal number and then store that to a variable and subtract it from the original number

    example

    @a = 2.75

    @b-2 = floor(2.75)

    @C = @a - @b-2 (this gives me 0.75)

    but is there a function that does this in SQL Server

    Cheers,

    Chandra

  • If you can't use convert(), you can always use cast(). BTW, I can't remember how floor() behaves for negative numbers, but I know there's a reason I end up using round() instead.

  • vchandm23 (8/8/2011)


    but is there a function that does this in SQL Server

    Not in any version of SQL Server that I know of. You're pretty much stuck with doing the math like you did.

    --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)

  • vchandm23:

    What about using modulus (%)? Like some flavor of the following:

    select replace(1234.4321 % 1 ,'0.','')

Viewing 15 posts - 1 through 14 (of 14 total)

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