aspose file tools*
The moose likes Beginning Java and the fly likes setText Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "setText" Watch "setText" New topic
Author

setText

Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
I have a value that has to be defined as a float. I'm trying to right this value to a text field using setText but everything that I have tried gives me a compile error. How do I handle this?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

setText() wants a String as an argument, so you need to convert your float to a String. There are (as is often the case) several ways to do this, but easy one is the static method String.valueOf(); there's an overloaded version of this for just about every primitive type. So you could say


[Jess in Action][AskingGoodQuestions]
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello,
There is another way of type casting a Float value to a String value.
float x = 0.0f;
String text = Float.toString(x);
Hope it is worth to you.


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setText