File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes float primitive and its.... crazyness?!?! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "float primitive and its.... crazyness?!?!" Watch "float primitive and its.... crazyness?!?!" New topic
Author

float primitive and its.... crazyness?!?!

Andree Charfen
Ranch Hand

Joined: Mar 24, 2004
Posts: 32
haha.. ok...
Maybe I am noone to call Mr.float primitive crazy.. but it seems crazy to me.
Ok... if you have a primitive member var its default is..... 0.0 buut... float... its not a floatating point type... so you cant asign for example 0.5? Why is this?
REGARDS!


yeeeehhhhaaaaaa<br />(riding the JVM)
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Andree,
I would say that in "literal" terms, the default value of a float is actually "0.0f". When you forget to append the "f", it will treat literals as literal double values. And since a double has more bytes than a float, the compiler will generate an error when you attempt to assign "0.5" to it. However, as I mentioned, setting a float the value of "0.5f" will work just fine for you.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: float primitive and its.... crazyness?!?!