• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why no String param constructor for Float objects

 
Sherry Nelson
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CLDC1.1 does not seem to support the String param constructor for Float objects. Same deal for Double & Integer objects ... I can, however, create all such objects from primitives.

Does anyone know why this is?

And, how else can I read a user's numeric entry from a textbox or textfield, then perform arithmetic operations on it?

thanks,
Sherry
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CLDC1.1 does not seem to support the String param constructor for Float objects. Same deal for Double & Integer objects ... I can, however, create all such objects from primitives.

Does anyone know why this is?

I think it is because that constructor using String as a parameter is expensive. Just guessing...

And, how else can I read a user's numeric entry from a textbox or textfield, then perform arithmetic operations on it?
[/QB]

In this case, you can read your text from the textfield by using textfield.getString(). Suppose the string you get is in the variable 's', then put that in the Float.parseFloat(s) and the resulting float is yours....

Hope it helps...
 
Sathya Srinivasan
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that the J2ME developers left out many of the convenience methods in order to reduce the size of the JAR file. Maybe they thought (which I agree with, if true) that people can always use other methods to simulate the same results.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sathya Srinivasan:
Maybe they thought (which I agree with, if true) that people can always use other methods to simulate the same results.


Simulating the Sherry's wanted result...
Float float = new Float(Float.parseFloat(yourTextfield.getString()));

Then you can use the variable "float" in performing arithmetic operations... Hope it helps...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic