Results 1 to 4 of 4
Thread: using decimal numbers
- 10-30-2010, 11:46 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
using decimal numbers
First off, I did search a bit. But being new and not really understanding much I'm not quite sure how to word things to get the answer I want. What I was able to find confused me more. But I did find a trend in answers, to which I'm sure someone will elude to.
Reading here and I don't quite understand it. (think it has something to do with not being able to see the result or what's being input)
Right now I've got this:
I think it should look something like this:Java Code:int p = Integer.parseInt(pres.getText());
But that gives me an error that says "cannot find symbol" and the 'temp.getText());' is underlined (I know that means that's the trouble spot).Java Code:int t = NumberFormat.getIntegerInstance(temp.getText());
So how should I fix this?
I have "java.text.NumberFormat" imported. And I think (from what I've found) there has to be a format and wording similar to the link I've posted ... "try" and "catch",, but where do user input numbers fit into those lines?
Not sure if it matters but I'm using NetBeans 6.9.1 and this is a jFrame application with tabs; very similar to what this tutorial taught me to do. Which I've noticed has the same problem. You can't input 30.5 hours worked or any decimal number. That is what i wish to fix and can not find how.
Also I'm am learning on my own from tutorials and searching. Never done any programming before. So be gentle please.
--JohnLast edited by iminhell; 10-31-2010 at 03:43 AM.
-
You may need to tell us what you are trying to do first as I don't see this fully explained anywhere in your post.
What is wrong with this? How does it not fulfill whatever criteria you have (again we need to know the criteria to be able to help you)?Right now I've got this:
Java Code:int p = Integer.parseInt(pres.getText());
The error is well deserved since if you read the API for NumberFormat you'll see that getIntegerInstance returns a NumberFormat object, not an int. Again, what are you trying to accomplish (Sorry if I'm sounding like a broken record)?I think it should look something like this:
But that gives me an error that says "cannot find symbol" and the 'temp.getText());' is underlined (I know that means that's the trouble spot).Java Code:int t = NumberFormat.getIntegerInstance(temp.getText());
- 10-31-2010, 03:41 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
lol
Was hoping someone would look at the tutorial link. It has the same loss of function I was dealing with.
After hours of searching and the loss of a rather large portion of my already thinning hair, I found the answer. It is located in this tutorial.
So I changed my first code to the now working code of:
Happens to be the only help I've read where the float function was mentioned. Not sure if it's correct, but it works and I'm going with it. Leave any problems for a battle another time.Java Code:float t, p, pci, fps; // Gets temperature from the text field, and then parses it to type float. t = Float.parseFloat(temp.getText()); p = Float.parseFloat(pres.getText()); //Simple statement for calculations pci = (float) (1.325 * (2.036254 * p / (459.67 + t))); fps = (float) Math.sqrt(1.4*1716*(t+459.67)); //Writes the total jLabel5.setText(String.valueOf(pci)); jLabel7.setText(String.valueOf(fps));
Like I'd mentioned, I was quite sure I was searching wrong. Just happened on this one by chance.
*I don't see any option to close or "label as solved". Not sure if you guys just let them drift away or what, but I think I'm good for now. Thanks for the time.Last edited by iminhell; 10-31-2010 at 03:44 AM.
-
Congratulations on solving it and especially on solving it yourself, as you will definitely learn from this experience.
To mark this thread as "solved" please click on the "Thread Tools" link near the top of this thread.
One last thing, consider using double rather than float since it is much more accurate with little extra cost.
edit: also, thanks for posting a solution, so now you can share the knowledge you've gained with others! :)Last edited by Fubarable; 10-31-2010 at 03:50 AM.
Similar Threads
-
converting a decimal to an int
By shuks in forum New To JavaReplies: 9Last Post: 10-12-2009, 09:41 AM -
round down to 2 sig. numbers after the decimal point
By soc86 in forum New To JavaReplies: 4Last Post: 01-16-2009, 06:17 PM -
Truncating decimal numbers in the output
By gbade in forum New To JavaReplies: 2Last Post: 11-21-2008, 06:25 PM -
printing two smallest numbers from a series of numbers
By trofyscarz in forum New To JavaReplies: 2Last Post: 10-14-2008, 11:46 PM -
numbers with two decimal places
By little_polarbear in forum New To JavaReplies: 8Last Post: 08-27-2008, 11:04 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks