Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help converting a string to an integer

    i have a dropdown of selects wher ethe options are
    ..
    ..
    ..
    "07:50"
    "08:00"
    "08:10"
    ..
    ..
    ..
    etc

    now i have a function that grabs the info from that and converts it into number of minutes..
    for all the numbers it works fine parseInt the value.. after spliting it by : into hours and minutes

    but with any number that is 08 or 09 it parseInts to 0 instead of 8 or 9

    any thoughts here's my function

    function checktimes() {
    v_early = String(document.addform.minTime[document.addform.minTime.selectedIndex].value);
    early_array = v_early.split(":");
    early_mins = parseInt(early_array[0]) * 60;
    early_mins += parseInt(early_array[1]);
    alert(early_mins);
    }

    just converts the hours/minutes to total minutes

    any help is appreciated thanks
    accordingtojosh@hotmail.com

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You have to tell parseInt() to use a base of 10. parseInt() by default attempts to determine the base of the output. Any string with a leading zero is interpreted as octal, or a base radix of 8.

    Easy fix.

    early_mins = parseInt(early_array[0], 10) * 60;
    early_mins += parseInt(early_array[1], 10);
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's working fine... What's the problem?

    (On this computer I'm using Win98 + IE 5.50.48)

    Mzzl, Chris
    My Website
    010100010011110101110100011011110111000001101000

  • #4
    New to the CF scene
    Join Date
    Dec 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, it worked after i made the change beetle recommended
    accordingtojosh@hotmail.com


  •  

    Posting Permissions

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