Hi Geeta! float a = 1; // 1 float b = 1L; // 2 float c = 1F; // 3 float d = 1.0; // 4 All floating point values are double by default.So in line 4 ,1.0 is a double and you are assigning it to a float(32 bits) which is a smaller container compared to double(64 bits).So it gives a loss of precision error.It can be compiled by applying a cast as follows: float d=(float)1.0 or by appending an f to the end of 1.0 i.e float d=1.0f
Hi Geeta, Working with money written by Thomas Paul is a good article. This helped me a lot.
Joined: Sep 18, 2003
Hi Cathy, I tried to go through the article but it seems a little difficult. Seems i need to study more on data types. Sagarika, thanks for ur reply but the explaination you gave didn't clear my doubt. If a float is double implicitly and because of loss of precision the compile time error is generated then why is it not the case with Long?