Professional Web Applications Themes

Decimal result - Microsoft SQL / MS SQL Server

Hi, I have select statement which returns value without leading zero: SELECT cast(field1 as decimal(38,2)) FROM table1 The result is: ..23 I would like that result is: 0.23 Does anybody know the answer? Thank you, Simon...

  1. #1

    Default Decimal result

    Hi,

    I have select statement which returns value without leading zero:

    SELECT cast(field1 as decimal(38,2)) FROM table1

    The result is:
    ..23

    I would like that result is:

    0.23

    Does anybody know the answer?

    Thank you,
    Simon


    Simon Guest

  2. #2

    Default Re: Decimal result

    SELECT cast(cast(.234223 as decimal(38,2)) as varchar(10))

    The question is WHY.
    It is good practice to do this at the presentation layer.

    "Simon" <si> wrote in message
    news:3f310ed4$s5.net... 


    raydan Guest

  3. #3

    Default Re: Decimal result

    Raydan,

    Actually, the value in question was of scale 2 & so, .2344 will need a scale
    of 4 for proper representation as DECIMAL. So, effectively, the 3rd
    parameter for STR has to be changed to 4. If the scale needs to be set as 2
    in the result, you are correct.

    --
    - Anith
    ( Please reply to newsgroups only )


    Anith Guest

  4. #4

    Default Re: Decimal result

    I was just nit-picking. :-)

    "Anith Sen" <com> wrote in message
    news:e%phx.gbl... 
    scale 



    raydan Guest

  5. #5

    Default Re: Decimal result

    Can I join in? Depending on the type of the input, there can
    be some surprises:

    declare v float
    set v = 0.235
    SELECT STR(v, LEN(v), 2)
    SELECT cast(cast(v as decimal(38,2)) as varchar(10))

    -- Steve Kass
    -- Drew University
    -- Ref: B50C89B7-8B02-4948-BD4B-13C25856642A

    raydan wrote:
     
    >scale
    >

    >2
    >

    >
    >
    >
    >[/ref]

    Steve Guest

  6. #6

    Default Re: Decimal result

    here you go about datatypes a g a i n....

    --
    -oj



    "Steve Kass" <edu> wrote in message
    news:phx.gbl... 
    > >scale
    > >
    > > [/ref][/ref]
    as 
    > >2
    > >
    > > 
    > >
    > >
    > >
    > >[/ref]
    >[/ref]


    oj Guest

  7. #7

    Default Re: Decimal result

    Just be glad I've been quiet about RAND(X) for a while... ;)

    SK

    oj wrote:
     [/ref]
    >as
    >
    > [/ref]
    >
    >
    >
    >[/ref]

    Steve Guest

  8. #8

    Default Re: Decimal result

    hehehehe....for a while...

    shouldn't you be answering the "Convert / Decimal / Float" post... <G>

    --
    -oj


    "Steve Kass" <edu> wrote in message
    news:e$phx.gbl... 
    > >as
    > >
    > > 
    > >
    > >
    > >
    > >[/ref]
    >[/ref]


    oj Guest

Similar Threads

  1. [PHP] How do I get the result of a Division to 2 decimal places?
    By Marek Kilimajer in forum PHP Development
    Replies: 1
    Last Post: September 9th, 03:10 PM
  2. Replies: 1
    Last Post: September 9th, 02:30 PM
  3. #24891 [Bgs]: Decimal equality incorrect result
    By jeff at tmtrading dot com in forum PHP Development
    Replies: 1
    Last Post: July 31st, 07:01 PM
  4. #24891 [Opn->Bgs]: Decimal equality incorrect result
    By sniper@php.net in forum PHP Development
    Replies: 0
    Last Post: July 31st, 06:35 PM
  5. Replies: 0
    Last Post: July 1st, 03:00 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139