RESULT IN FLOAT

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • T.S.Negi

    RESULT IN FLOAT

    HI,
    I WANT THIS TO PRODUCE EXACT RESULT. (IN SQL SERVER)

    SELECT (23 / 233) * 100

    THE ANSWER SHOULD COME 9.871244635 OR 9.87
    BUT IT RETURNS 0.

    I WANT THE PERCENTAGE.

    HOW TO HANDLE THIS KIND OF PROBLEM.
    IS THERE ANY SET COMMAND FOR IT?


    THANKS


    T.S.NEGI
    tilak.negi@mind-infotech.com
  • Erland Sommarskog

    #2
    Re: RESULT IN FLOAT

    [posted and mailed, please reply in news]

    T.S.Negi (tilak.negi@min d-infotech.com) writes:[color=blue]
    > I WANT THIS TO PRODUCE EXACT RESULT. (IN SQL SERVER)
    >
    > SELECT (23 / 233) * 100
    >
    > THE ANSWER SHOULD COME 9.871244635 OR 9.87
    > BUT IT RETURNS 0.[/color]

    This because in T-SQL, as in several other programming languages, /
    yields integer division if both numbers are integer. The simplest
    way is to say (1.0*23/233) * 100. In this way you get a floating-
    point number.




    --
    Erland Sommarskog, SQL Server MVP, sommar@algonet. se

    Books Online for SQL Server SP3 at
    SQL Server 2025 redefines what's possible for enterprise data. With developer-first features and integration with analytics and AI models, SQL Server 2025 accelerates AI innovation using the data you already have.

    Comment

    Working...