• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting integer to a textbox

 
mo robertson
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i have an integer called 'Price' which has been declaired on a class
i want to set price to a textbox, but it doesnt let me becuase its integer, string works fine. how would this be ?

h[count].Price= "" + jTextField7.getText ();
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mo robertson:
ok i have an integer called 'Price' which has been declaired on a class
i want to set price to a textbox, but it doesnt let me becuase its integer, string works fine. how would this be ?

h[count].Price= "" + jTextField7.getText ();


Hi mo,


Normally your integer would be called 'price' because only classes should be capitalized.

If your price can contain cents, then you can have a proble with decimal point.

What you will get from the text box, even if the user type all numeric digits, is an ascii string. You can call Integer.parseInt (jTextField7.getText ()) to convert it to an int. You can place that in a try/catch block in case the user did not type a convertable number.

Mo used to be a famous comedian in Australia over 50 years ago so I love your name.

Ed
[ May 21, 2004: Message edited by: Eddie Vanda ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic