Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Norm

Thread: Basic Code explination

  1. #1
    Dark Knight is offline Member
    Join Date
    Feb 2014
    Posts
    20
    Rep Power
    0

    Default Basic Code explination

    Hi,

    Im trying to teach myself a bit of java and came across the following line of code in the degrees to Fahrenheit converter tutorial:

    int tempFahr = (int)((Double.parseDouble(tempTextField.getText()) )
    * 1.8 + 32);

    I know what the code does in that it is getting the value that the user has input in text field tempTextField and is applying the mathematical calculation to convert to Fahrenheit and assigning the result to the variable tempFahr. I am going to list a number of things I assume is going on here and if anyone could correct me if im wrong or confirm if I am correct that would be brilliant.

    • I am guessing any value input into a text box is considered a string?
    • I am guessing that Double.parseDouble takes in a string and converts it to a double.
    • I am assuming that by simply putting (int) in front of (Double.parseDouble(tempTextField.getText())) * 1.8 + 32) that it calculates the value and converts it to an int?
    • The tutorial says this example is not localizable because the parseDouble method is not localizable - what does it mean by localizable?


    Thanks for taking the time to look at this.

  2. #2
    typedef is offline Member
    Join Date
    Feb 2014
    Posts
    52
    Rep Power
    0

    Default Re: Basic Code explination

    Sorry about your last part - I have no idea about "localizable" - but as far as everything else your right. Only thing you should take note about it is that conversion to an int from a double implies truncation not rounding. Therefore 10.9 becomes just 10 in case you didn't already know.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,390
    Rep Power
    25

    Default Re: Basic Code explination

    what does it mean by localizable?
    Different cultures have different usage of symbols in numbers.
    For some the . and , are reversed:
    1,234.5
    1.234,5
    typedef likes this.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    typedef is offline Member
    Join Date
    Feb 2014
    Posts
    52
    Rep Power
    0

    Default Re: Basic Code explination

    One more term for my vocabulary

Similar Threads

  1. help with basic code!!!
    By GerD in forum New To Java
    Replies: 19
    Last Post: 10-06-2012, 11:36 PM
  2. SwingWorker Explination
    By aadem in forum Advanced Java
    Replies: 4
    Last Post: 03-22-2011, 05:34 PM
  3. very basic code
    By BlueJ2008 in forum New To Java
    Replies: 1
    Last Post: 10-14-2008, 01:40 PM
  4. help with basic java code
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •