This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes parseDouble Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "parseDouble Problem" Watch "parseDouble Problem" New topic
Author

parseDouble Problem

henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
Hello,
Below is the printout in Netbeans of my JavaBean ouput. The last value was typed in the TextField was 5.1 for the audio value. I have tested it may times and it always come out as 0.0
Further down is the code to parse my String to a double from the TextField.
If I need a double, ddoes the user need to type it in with a decimal point in between two numbers. Would anyone guess why it comes out as 0.0?

Here is a link to a screenshot to give you an ideaof what it is I am working on. Thanks.

http://pollscanada.com/screenshot.html


init:
deps-jar:
compile-single:
run-single:
Cabin Fever, Horreur, 2002, 92 Minutes, Audio 0.0
BUILD SUCCESSFUL (total time: 0 seconds)


Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

This line

double audio2 = Double.parseDouble(audio1);

declares a local variable and initializes it. Since the block it's in ends immediately after, nobody ever uses this variable. Perhaps there's also a member variable named audio2 that you're trying to assign to? In that case, you need to remove the "double", which turns this from a declaration of a new variable into a simple assignment to an existing variable.


[Jess in Action][AskingGoodQuestions]
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
Thank you for your response. It is quite mind-boggling. I will try your suggestion.
henri henri
Ranch Hand

Joined: Oct 03, 2005
Posts: 115
It turns out it was an oversight of mine. I had declared my double twice. Once as a member and then inside a try.block
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Yep. Isn't that what I said?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: parseDouble Problem
 
Similar Threads
Changing Printer Ink Colour
Data Transfer
Static Methods Don't Work
setValueAt() and JTable
Matching HashMap Key To Value