Type conversion

S

Scott Allen

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.
 
K

Karl Seguin

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
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top