File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Negative Floating point numbers
Joined: Aug 20, 2002
May 24, 2004 10:29:00
Floating point numbers when declared
ie., float f = 3.45f;
requires the "f" or "F" appended after the numeral. Now if i declared,
float f1 = -32;
it does not require an "f" or "F" appended after the number. Can anyone explain why?
author and iconoclast
Joined: Jul 08, 2003
May 24, 2004 10:34:00
Because "-32" isn't a floating point number, it's an int, and it's legal to assign an int value to a float. If you wrote "-32." (with a decimal point at the end) you'd find that the "f" was required again.
[Jess in Action]
Joined: Nov 05, 2003
May 24, 2004 20:06:00
an integer can be cast to a floating point number without an explicit cast and -32 is an integer.
"In theory, there is no difference between theory and practice. But, in practice, there is."<br /> - Jan L.A. van de Snepscheut
Marilyn de Queiroz
Joined: Jul 22, 2000
May 25, 2004 01:15:00
floating point number in
, not a float
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link:
subject: Negative Floating point numbers
Assignment to float
Question from JQ+
java rule round up #113
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015