• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setText

 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ransika deSilva
Ranch Hand
Posts: 524
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic