Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Back to Basics

Status
Not open for further replies.

woyler

Programmer
Jun 20, 2001
678
US
Hi all,
Can someone explain to me why MS returns the following values with these function calls?

convert.toint16(1.5) = 2 (this is expected)
convert.toint16(2.5) = 2 (huh?)
convert.toint16(3.5) = 4 (this is expected)
convert.toint16(4.5) = 4 (huh?)

the same is true for math.round. Can someone shed some light on this for me?
regards,
Bill
 
Wow, stumped me. I even plugged it in here and got the same from both convert and ctype. I would have expected either a traditional rounding (.5 = 1, .4 = 0) or a truncate (.5 = 0), but not the inconsistent treatment.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Bill,
Take a look at the help for convert. I know it sounds very screwed up, but according to the help, your examples are working as they should. (here is a part of the explanation):

Return Value
value rounded to the nearest 16-bit signed integer. If value is halfway between two whole numbers, the even number is returned; that is, 4.5 is converted to 4, and 5.5 is converted to 6.
 
PRPhx,
Thanks for the info, and I noticed that pattern as well. My question still is why? I can not find a MS answer on this. There has to be some sort of explanation other then Joe Programmer @ MS ate too many "special brownies
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top