Professional Web Applications Themes

show only 2 decimals - Microsoft SQL / MS SQL Server

What is the syntax to show only 2 decimals and if there is no decimals, I will assign .00 at the end. Select Discount, Total From Table1 Thanks. Karen...

  1. #1

    Default show only 2 decimals

    What is the syntax to show only 2 decimals and if there is no decimals, I
    will assign .00 at the end.

    Select Discount, Total
    From Table1

    Thanks.

    Karen


    Karen Guest

  2. #2

    Default Re: show only 2 decimals

    Try:

    Select Discount, cast (Total as numeric (5, 2))
    From Table1


    --
    Tom

    ---------------------------------------------------------------
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
    SQL Server MVP
    Columnist, SQL Server Professional
    Toronto, ON Canada
    www.pinnaclepublishing.com/sql


    "Karen" <com> wrote in message news:#phx.gbl...
    What is the syntax to show only 2 decimals and if there is no decimals, I
    will assign .00 at the end.

    Select Discount, Total
    From Table1

    Thanks.

    Karen



    Tom Guest

  3. #3

    Default Re: show only 2 decimals

    use decimal datatype with precision a 2
    Ex:
    declare x int
    select x=2
    select convert(decimal(5,2),x) deci

    --
    -Vishal

    "Karen" <com> wrote in message
    news:#phx.gbl... 


    Vishal Guest

  4. #4

    Default Re: show only 2 decimals

    Karen wrote: 

    This should be done in the client pogram, but ... 
    Numbers don't have format. Strings do. So use convert to cast Total as money
    and then convert it to varchar, using the 1 as the style argument:
    Select Discount,
    convert(varchar(10),cast(Total as money),1) ...

    Look up CONVERT in BOL for more details

    HTH,
    Bob Barrows


    Bob Guest

  5. #5

    Default Re: show only 2 decimals

    Understood now. Thank you all very much!

    Karen

    "Karen" <com> wrote in message
    news:%phx.gbl... 


    Karen Guest

Similar Threads

  1. 14 decimals after comma
    By Dave_Saunders@adobeforums.com in forum Adobe Indesign Macintosh
    Replies: 29
    Last Post: September 30th, 01:09 PM
  2. chart decimals
    By CFkubio in forum Coldfusion - Getting Started
    Replies: 6
    Last Post: October 13th, 04:30 PM
  3. CFCHART AND DECIMALS
    By jgarciam in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: May 12th, 08:19 AM
  4. Decimals not Getting into ASP
    By msnews.microsoft.com in forum ASP Database
    Replies: 0
    Last Post: July 15th, 07:44 PM
  5. Formatting the decimals
    By Mallik in forum PERL Beginners
    Replies: 3
    Last Post: January 29th, 11:17 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