Moving the decimal

  • Hi,

    I have a decimal field (10,4) that has values in it like:

    0.0123

    0.0063

    0.0595

    I need a way in my select statement to make them look like:

    1.23

    0.63

    5.95

    I've tried this but it's not correct:

    SELECT

    CAST([Overtime Actual Percentage].[Actual Overtime Percentage]*100 AS DECIMAL(20)) AS 'Actual Overtime Percentage',

  • Just convert it to a decimal(10,2) instead of decimal(20) after you multiply by 100.

    convert(decimal(10,2), mydec * 100)

  • Even better would be a decimal(8,2) 🙂

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (8/14/2013)


    Even better would be a decimal(8,2) 🙂

    You'd get an error if you had a number that filled up that decimal(10,4) though, would you not?

    123456.7890 * 100 would not fit into a decimal(8,2).

  • works fine...thanks!

  • roryp 96873 (8/14/2013)


    Luis Cazares (8/14/2013)


    Even better would be a decimal(8,2) 🙂

    You'd get an error if you had a number that filled up that decimal(10,4) though, would you not?

    123456.7890 * 100 would not fit into a decimal(8,2).

    And I got it completely wrong. In my head I only thought on truncating the last 2 decimals (I'm not sure why) :hehe:

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 6 posts - 1 through 5 (of 5 total)

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