0
Hey
Precision is the main difference.
Int - 32 bit - No suffix
Float - 7 digits (32 bit) - 'f' suffix
Double-15-16 digits (64 bit) - 'd' suffix
As Nilesh said, if you don't specify any suffix to a number then it will be co sidered as integer value i.e int
Q.Why is f required after 0.1 in both cases ? Main doubt is "f" is called float. Since the data type is float,Why f needs to be put after 0.1 ?
A. As float has a suffix f and double as d, hence, double has more range than float, so in this case, type casting has been applied, as float has smaller value than double, it has adjusted in that datatype without any problem but if you have been typecasted from double to float, it will loose its value and retains to its max value.
Good Luck !!
Accepted 1
please mark my answer as accepted if it satisfied your question.
1
If you don't specify any suffix, then the integer values are evaluated as per the following sequence:
int
uint
long
ulong
The suffix L denotes a long in your value 234L.
When you use the suffix L, the type of the literal integer is determined to be either long or ulong, depending on its size. In your case, it is long because it less than the range of ulong.
A common use of the suffix is to call overloaded methods by passing in values directly or when passig in "var" type variables.
similar thing applies in case of f suffix.
please see below code, or download attached project and see yourself.
- class Program
- {
- static void Main(string[] args)
- {
- SampleMethod(5);
- SampleMethod(5L);
-
- Console.WriteLine("------------");
-
- var myVal1 = 5;
- SampleMethod(myVal1);
-
- var myVal2 = 5L;
- SampleMethod(myVal2);
-
- Console.ReadKey();
- }
-
- public static void SampleMethod(int i)
- {
- Console.WriteLine("Called integer version of SampleMethod");
- }
-
- public static void SampleMethod(long l)
- {
- Console.WriteLine("Called long version of SampleMethod");
- }
- }

0
Hey
Type casting means converting One data type to another data type .
You can read the below link for detail discussion
https://stackoverflow.com/questions/618535/difference-between-decimal-float-and-double-in-net
0
Hi,
Why is f required after 0.1 in both cases ? Main doubt is "f" is called float. Since the data type is float,Why f needs to be put after 0.1 ?
A. As float has a suffix f and double as d, hence, double has more range than float, so in this case, type casting has been applied, as float has smaller value than double, it has adjusted in that datatype without any problem but if you have been typecasted from double to float, it will loose its value and retains to its max value.
In the above question you said :type casting...what is it means?
Also are these below both same: still some confustion exisits. can you be more clear
float x = 0.5f
float x = 0.5
double x = 0.5d
double x = 0.5