SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2006
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display as Percentage - SQL Server

    Hi,

    My code below now gives a result but with too many decimal places...Here's the output:

    7941250.000000%

    Is this the correct way to display as Percentage? And how do I reduce the number of 0s after the decimal?

    Thanks.


    Code:
    DECLARE @StartingNum int
    DECLARE @NumDifference numeric (38,6)
    
    Declare @ResultsData as table
    (
    MyPoints varchar(80) null
    )
    
    
    insert into @ResultsData
    (
    CAST(((cast(NumDifference as numeric(38,2))/
    cast(@StartingNum as numeric(5,2)))*100) AS VARCHAR(56) )+'%' AS MyPoints 
    )

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    best practice is to do formatting in the front end application

    the query should return plain numbers, not formatted character strings

    even calculations such as percentages should really be done in the front end
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •