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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cast all? 1

Status
Not open for further replies.

stormbind

Technical User
Mar 6, 2003
1,165
0
0
GB
Hi,

I'm using a Java library that accepts only float values. This is fine except Java defaults to doubles.

getResult(0.4); // Java assumes its a double and complains its not a float

Casting is a pain when you're doing it every line..

Is there a way to make Java default to using floats, or convert automatically, or do something that mitigates writing (float)0.. every other line?

Thanks :)

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
In C/C++ you can put an 'f' after the number to make it a float. Ex. getResult( 0.4f );
I haven't tried it in Java, but try it and see.
 
Yes, it also works in Java

Another workaround is using a float variable for asignments.

Cheers,
Dian
 
cpjust wins a hug.. i mean a star.



--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top