Visual studio feeds

All Visual Studio blogs in one place

Subscribe

Enter your email address:

Delivered by FeedBurner

Increase your website traffic with Attracta.com

Google+

Contact

Email:
Subject:
Message:
Anti-spam: How many eyes has a typical person?

Follow us on FB

Search

VB Quark #4: type literals

AddThis Social Bookmark Button
Do you know why you can’t write this code in VB:    Dim x = 123456789.0123456789
Answer: The IDE won’t let you If you try to write that code the IDE will truncate the number, giving :    Dim x = 123456789.01234567
To include all the decimal places you need to be using the Decimal type. To do this you indicate the constant is of type decimal by adding the suffix D on the end, eg:    Dim x = 123456789.0123456789D
The reason for this is VB treats numeric literals as of type Double by default if they have a
decimal place. If there is no decimal place in the literal then the value is consider to be an Integer (Int32), or if it is too large for an Integer, it’s considered to be a Long (Int64). If you want the literal as a type other than Double, Integer or Long you need to either convert using CType, CShort, CSng etc, or add a type literal suffix. The following is the complete list for numeric type literal suffixes in VB: Suffix Type F Single R Double D Decimal

Home : Blog List : Bill's random thoughts... : VB Quark #4: type literals