Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare a float with NULL

Status
Not open for further replies.

tyris

Programmer
Nov 2, 2000
311
FR
if i want to compare this float with a NULL value ?

i mean :
i do have a float in an object:

myObj.Myfloat

if i do ( myObj.Myfloat.equals(NULL) it tels me that NULL is not defined
Best regards X-),
Elise
 
Try "NULL"
This might not work as I'm new to Java myself.
 
if the float in your object is of type Float then you can use
(myObj.Myfloat == null)
but if you use the primitive float, you can't compare it to null. There i would recommend the NaN value as initialisation and comparing.

Hope this helps,
Steven.
 
well is my case i use a primitive float.

the problem is that i initialise my float this way :

myObj.Myfloat = Float.parseFloat(request.getParameter("budget"));

if the parameter budget is equal to nothing what can i do for if (myObj.Myfloat == "NULL" ) ? i can't put a "null" value in a float. Best regards X-),
Elise
 
try this in instead:

if(request.getParameter("budget") != null)
myObj.Myfloat = Float.parseFloat(request.getParameter("budget"));

Hope this helps,
Steven.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top