• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

parseFloat and Float.NaN??

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public float parseFloat( String s )
{
float f = 0.0f; // 1
try
{
f = Float.valueOf( s ).floatValue(); // 2
return f ; // 3
}
catch(NumberFormatException nfe)
{
f = Float.NaN ; // 4
return f; // 5
}
finally {
return f; // 6
}
return f ; // 7
}
I am finding these words new.
I dont understand what doed these words mean to say and wht is their output..
Can any one explain me in detail?
Sonir
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your example, parseFloat is just an identifier that names a method.
just like in this line of code:
public static void main(String[] args)
the word "main" is an identifier and names this method.
NaN stands for "Not a number." It is part of the IEEE754 standard for dealing with floating point operations.
Basically, this allows for floating point operations without having to raise exceptional conditions.
For example, what is the result of this operation
double number = 0.0/0.0; //number is undefined!
double imaginary = Math.sqrt(-2.0); //not a "Real" number
The important point here is to remember that floating point operations NEVER result in any exceptions being thrown.
Rob
[ January 10, 2002: Message edited by: Rob Ross ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can always look up the documentation on Sun's site at
http://java.sun.com/j2se/1.3/docs/api/index.html
Scroll through the box on bottom left, to find the class or interface you are looking for.
It lists ALL the fields and methods of all the classes.
Hope this helps.
 
Normally trees don't drive trucks. Does this tiny ad have a license?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic