aspose file tools*
The moose likes Beginning Java and the fly likes Negative Floating point numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Negative Floating point numbers" Watch "Negative Floating point numbers" New topic
Author

Negative Floating point numbers

charu latha
Ranch Hand

Joined: Aug 20, 2002
Posts: 67
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?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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][AskingGoodQuestions]
Preetham Chandrasekhar
Ranch Hand

Joined: Nov 05, 2003
Posts: 98
exactly....
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
Sheriff

Joined: Jul 22, 2000
Posts: 9052
    
  12
The default floating point number in Java is a double, not a float


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Negative Floating point numbers