aspose file tools*
The moose likes Java in General and the fly likes casting: float to Float Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "casting: float to Float" Watch "casting: float to Float" New topic
Author

casting: float to Float

Steve Rodgers
Greenhorn

Joined: Jul 03, 2003
Posts: 21
I searched the forum and nothing quite fit what I was looking for. This is pretty straight forward but I'm missing it. Too tired (or something).

I have a String (XML) that I cast to float (so I can use the absolute value method). Now I need to make that float a type of Float.



steveNumber is type float. How to make it Float? If there are other methods than the Math.abs to drop a (+ or -) sign I'll go straight from String to Float.

Thanks in advance.
[ February 18, 2005: Message edited by: Steve Rodgers ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Float f = new Float(steveNumber);

Once you've created a Float, you can't change its value, so I think this is basically your only choice.


[Jess in Action][AskingGoodQuestions]
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Steve Rodgers:
I have a String (XML) that I cast to float . . . . Now I need to make that float a type of Float.
First a word on terminology. Casting is a specific operation in Java where you change the reference type from one class/interface to another using put "(class/interface)" in front of the reference. It does not affect the object to which the reference points. What you're talking about in both cases is conversion.

Now, to convert a float to a Float, you simply create a new Float object from the float primitive:
Steve Rodgers
Greenhorn

Joined: Jul 03, 2003
Posts: 21
Thanks for answering so quickly. I read a little more after my posting about Float versus float, etc... I needed the refresher.

Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: casting: float to Float