• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

type casting

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...
I want to that why in java we can't do type casting from higher datatype to lower dataype.I mean
float f=2.45f;
int i=(float)f;

What exactly happens here at at memory level.Is it because of the two different way bot the data type are represented internally.If yes.. can someone pls explain it.

Thanks.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please note that you are not doing a cast from a float to an int, you are just trying to assign a float to an int.

The correct option would be:
int i=(int)f;

And then i=2.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!