View Single Post
  #9 (permalink)  
Old January 3rd, 2011, 10:37 AM
DrPurdum DrPurdum is offline
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default Program constants

Yep, that's right.

Any time the compiler sees a numeric constant in the source code without a trailing decimal point, it will automatically assume it's an integer. If you want it to be a floating point number, as is the case here, you should add ".0" after the numeric constant to inform the compiler you want to do floating point operations on the number. Likewise, if you want to use a long data type constant, you should add a capital ell after the number, as in "55L", which would tell the compiler you want to use a long data type. (A lower case ell is difficult to read, as it looks like a pure number: "55l" which uses an ell, but looks like a one's digit.) Also, these data type modifiers (see suffixes, data types in the book's Index for a more complete list) help document any reader of your code that the number is something other than an integer number.

Thanks for the kind words about the book...it's sincerely appreciated.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
The Following User Says Thank You to DrPurdum For This Useful Post:
RyanL (January 4th, 2011)