You are here: Re: PRINT 1/(1+26)=0? « MsSQL Server « IT news, forums, messages
Re: PRINT 1/(1+26)=0?

Posted by Roy Harvey on 11/20/06 21:28

If any one of the operators had a decimal point then the results would
have had a decimal point. Performaing pure integer arithmatic, as in
the original example, returns an integer result.

Roy Harvey
Beacon Falls, CT

On 20 Nov 2006 12:57:04 -0800, mpaine@htxml.com wrote:

>Ok, I just figured it out:
>
>
>
>DECLARE @A int
>DECLARE @B int
>DECLARE @C float
>
>SET @A = 1
>SET @B = 26
>SET @C = CAST(@A AS float) / (CAST(@A AS float) + CAST(@B AS float))
>PRINT @C
>
>This is unlike any other programming language that I have used before
>-- so strange.
>
>mpaine@htxml.com wrote:
>> Why does this T-SQL round incorrectly?
>>
>> PRINT 1/(1+26)
>>
>> when it should be 0.037037037?
>>
>> Thanks,
>> Michael

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация