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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    < Compares String instead of Double

    Code:
    var all_cryptsy = <?php
            echo file_get_contents(
                    'http://pubapi.cryptsy.com/api.php?method=marketdatav2');
            ?> ;
    
    var col_ltc_cryptsy = all_cryptsy.return.markets['COL\/LTC'];
    
    var all_coin_e = <?php
            echo file_get_contents(
                    'https://www.coins-e.com/api/v2/markets/data/');
            ?>
    
    var col_ltc_coin_e = all_coin_e.markets.COL_LTC;
    
    if(col_ltc_coin_e.marketdepth.bids[0].q<=
    col_ltc_cryptsy.sellorders[0].quantity)
                     {
                         qty_col_ltc_coin_e_cryptsy = col_ltc_coin_e.marketdepth.bids[0].q;
                     }
                     else
                         {
                             qty_col_ltc_coin_e_cryptsy = col_ltc_cryptsy.sellorders[0].quantity;
                         }
    What I believe (I could be wrong) is happening is that the if statement is comparing the Objects as string. So, cr is always < co in the If statement. What I want it to do is compare the double values that are stored in the objects. Any ideas as to a solution would be greatly appreciated. Thanks in advance.
    Last edited by vinyl-junkie; 12-25-2013 at 06:25 AM. Reason: Corrected code tags

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,983
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Javascript doesn't have doubles - in fact there is only one type of number, that can have decimals or not which makes it much simpler than other languages. To cast (coerce) a string to a number all you have to do is this:
    Code:
    var three = Number("3");
    I couldn't find cr or co in your code, and don't know where you are getting your inputs from, but maybe this is what you are trying to do:
    Code:
    if(Number(col_ltc_coin_e.marketdepth.bids[0].q)<=
    Number(col_ltc_cryptsy.sellorders[0].quantity))
    you may want to check that your strings can in fact be converted to numbers, otherwise you will get NaN (not a number) which can mess up your calculations, too


  •  

    Posting Permissions

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