Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

float numbers
Hi!

How do I do to make t-sql not rounding the result that i returned?

For example:
0.9616458*60 = 57,698748 (in any calculator)

while following:
--------------------------------
declare @a float
declare @b int

set @a=0.9616458
set @b=60

print @a*@b
---------------------------------
will show :57.6987

How do I do to make MSSQL to show me the value whothout rounding it?

Thanks!


Report this thread to moderator Post Follow-up to this message
Old Post
homa@havet.se
04-03-06 02:30 PM


Re: float numbers
Use SELECT:

select @a*@b

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON   Canada
.
<homa@havet.se> wrote in message
news:1144073554.334910.187210@g10g2000cwb.googlegroups.com...
Hi!

How do I do to make t-sql not rounding the result that i returned?

For example:
0.9616458*60 = 57,698748 (in any calculator)

while following:
--------------------------------
declare @a float
declare @b int

set @a=0.9616458
set @b=60

print @a*@b
---------------------------------
will show :57.6987

How do I do to make MSSQL to show me the value whothout rounding it?

Thanks!


Report this thread to moderator Post Follow-up to this message
Old Post
Tom Moreau
04-03-06 04:27 PM


Re: float numbers
Hi! Itried your code and it works fine in the example I gave but not
when I implement it in my code:

declare @x float(53)
declare @grades int
declare @minutes int
declare @seconds float(53)
declare @minwithrest float(53)
declare @leftover float(53)

select @x = 57.66602743
select @grades  = floor(@x)
select @leftover = @x-@grades
select @minwithrest = (@leftover * 60)
select @minutes = floor(@minwithrest)
select @seconds = (@minwithrest - @minutes) * 60

print  @grades
print @minutes
print @seconds


gives me 57.6987 as @seconds while it should be  57,698748

thanks!


Report this thread to moderator Post Follow-up to this message
Old Post
homa@havet.se
04-03-06 04:27 PM


Re: float numbers
sorry.  I meant that it gives me 57.698747999999114 and It should be
57,698748  .
(The print is replaced by select)


Report this thread to moderator Post Follow-up to this message
Old Post
homa@havet.se
04-03-06 04:27 PM


Re: float numbers

I ran the 2nd code you've posted and I get the 57.6987 result


Report this thread to moderator Post Follow-up to this message
Old Post
gabe101
04-03-06 04:27 PM


Re: float numbers
Again, use SELECT:

select @seconds

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON   Canada
.
<homa@havet.se> wrote in message
news:1144077300.519079.316740@t31g2000cwb.googlegroups.com...
Hi! Itried your code and it works fine in the example I gave but not
when I implement it in my code:

declare @x float(53)
declare @grades int
declare @minutes int
declare @seconds float(53)
declare @minwithrest float(53)
declare @leftover float(53)

select @x = 57.66602743
select @grades  = floor(@x)
select @leftover = @x-@grades
select @minwithrest = (@leftover * 60)
select @minutes = floor(@minwithrest)
select @seconds = (@minwithrest - @minutes) * 60

print  @grades
print @minutes
print @seconds


gives me 57.6987 as @seconds while it should be  57,698748

thanks!


Report this thread to moderator Post Follow-up to this message
Old Post
Tom Moreau
04-03-06 04:27 PM


Re: float numbers
At this point, I'm confused about what result you are looking for.  Use
 convert(decimal(X,Y)
,@seconds) to fine-tune the result you need.  X can
be as large as 38 places and Y is your tunable decimal size.

HTH,
Gabe


Report this thread to moderator Post Follow-up to this message
Old Post
gabe101
04-03-06 04:27 PM


Re: float numbers
Try:

select
cast (@seconds as numeric (8, 6))


--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON   Canada
.
<homa@havet.se> wrote in message
news:1144077414.697728.270000@v46g2000cwv.googlegroups.com...
sorry.  I meant that it gives me 57.698747999999114 and It should be
57,698748  .
(The print is replaced by select)


Report this thread to moderator Post Follow-up to this message
Old Post
Tom Moreau
04-03-06 04:27 PM


Re: float numbers
I get:

57.698748


--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON   Canada
.
"gabe101" <gabe101@gmail.com> wrote in message
news:1144078109.143813.199680@z34g2000cwc.googlegroups.com...


I ran the 2nd code you've posted and I get the 57.6987 result


Report this thread to moderator Post Follow-up to this message
Old Post
Tom Moreau
04-03-06 04:27 PM


Re: float numbers
Tom,

Why do you suppose that is?  Is it our versions?  I'm on 8.00.760...


Report this thread to moderator Post Follow-up to this message
Old Post
gabe101
04-03-06 04:27 PM


Sponsored Links





Last Thread Next Thread
Pages (2): [1] 2 »
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 08:02 PM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006