Type conversion

  • Thread starter Thread starter Guest
  • Start date Start date
If you have a numeric literal in the code like 0.5342, the compiler will
treat the value as a double by default (64 bit floating point value).

In this case the suffix of F tells the compiler to treat the literal as a
float (32 bit) instead. The cast is not needed in this case.
 
Aye...the F is a type suffix which helps the compiler know which type you
are talking about when it can't necessarily tell.

F or f is float
D or d is double (the default)
M or m is decimal

that's for real numbers....integer values also have them for like U/u L/l
and combination of those (unsigned int, long, unsigned long ...)

There are probably more. VB.Net also makes use of them , such as with "a"c
to represent a character (notice the c after the string literal)....since
single quotes aren't available...

Karl
 
These can be important, especially in performaing math with literal numeric
values. For example:

double d = 1.2345678

double dx = d + (1d / 1200d) //1.2354011333333333333333333333333
double dy = d + (1 / 1200) //1.2345678

You will get 2 diffferent results from these 2 apparently identical
operations. This is due to the way the parenthetical numeric expression is
treated by the CLR.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
Back
Top