Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Java SE 8 for the Really Impatient
this week in the
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 Java is a
, 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
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: Negative Floating point numbers
Question from JQ+
java rule round up #113
Assignment to float
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014