Hello, all. Tired of trying to figure out SQLs rounding scheme. If I issue
:
select (540/60)/60, I'd like to get .15 however I get 0.
How can I get the .15 result I want?
Thanks
Rozselect (540/60)/60.0
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Roz" <Roz@.discussions.microsoft.com> wrote in message
news:21B68ED2-CA86-43D8-AD1A-F970E0CD37AC@.microsoft.com...
> Hello, all. Tired of trying to figure out SQLs rounding scheme. If I iss
ue:
> select (540/60)/60, I'd like to get .15 however I get 0.
> How can I get the .15 result I want?
> Thanks
> Roz|||To get a decimal result, you have to use at least one decimal operand. When
you use integer operands, you get an integer result.
SELECT ( 540.0 / 60 ) / 60
Use CAST or CONVERT functions if you want to convert an integer datatype to
numeric/decimal datatype with required precision.
Anith|||The problem is that you haven't specified a datatype explicitly so SQL
treats 60 as an integer and you get an integer division. To avoid this use a
NUMERIC datatype for example, or include decimals to imply a NUMERIC:
SELECT (540.0/60.0)/60.0
David Portas
SQL Server MVP
--|||Folks,
Thanks. These all worked beautifully!!!!
Roz
"David Portas" wrote:
> The problem is that you haven't specified a datatype explicitly so SQL
> treats 60 as an integer and you get an integer division. To avoid this use
a
> NUMERIC datatype for example, or include decimals to imply a NUMERIC:
> SELECT (540.0/60.0)/60.0
> --
> David Portas
> SQL Server MVP
> --
>
>|||Try this...
SELECT RTRIM((CONVERT(FLOAT(2),
540)/CONVERT(FLOAT(2),60))/CONVERT(FLOAT(2),60))
Regards
Sivakumar
"Roz" wrote:
> Hello, all. Tired of trying to figure out SQLs rounding scheme. If I iss
ue:
> select (540/60)/60, I'd like to get .15 however I get 0.
> How can I get the .15 result I want?
> Thanks
> Roz
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment