Hack Forums
[Javascript] Convert something loaded from website to an int and multiply - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [Javascript] Convert something loaded from website to an int and multiply (/showthread.php?tid=5806319)



Convert something loaded from website to an int and multiply - Konstantinos - Mar 1, 2018

So, I want to put that in a variable (var total_rece_btc), the load part, where it is being converted to an INT and multiplied by 0.00000001
Code
$('#total_received_btc').load('https://blockchain.info/q/addressbalance/' + '1EzwoHtiXB4iFwedPr49iywjZn2nnekhoj' + '?confirmations=0');

Thanks in advance  🤝


RE: Convert something loaded from website to an int and multiply - Nachfolger - Mar 1, 2018

Does that page return a string or something?

Do:
Code
parseInt(total_rece_btc) * 0.000001

I'm not sure why you're using .load to get the variable. Do this instead:
Code
$.get('https://blockchain.info/q/addressbalance/' + '1EzwoHtiXB4iFwedPr49iywjZn2nnekhoj' + '?confirmations=0', function(d) {
      $('#total_received_btc').text(parseInt(d) * 0.00000001);
});
Side note: So I don't get chastised, you should probably throw a check to make sure the page returns a parsable string/int. Otherwise the text for #total_received_btc will end up being something like "undefined" or "not a int" or like "false" and that's obviously a problem for you and your users.


RE: Convert something loaded from website to an int and multiply - Konstantinos - Mar 1, 2018

(Mar 1, 2018 02:19 PM)Nachfolger Wrote:  Does that page return a string or something?

Do:
Code
parseInt (total_rece_btc) * 0.000001

Tried this thing, wont work:
Code
var total_received_btc = parseInt(load('https://blockchain.info/q/addressbalance/' + '1EzwoHtiXB4iFwedPr49iywjZn2nnekhoj' + '?confirmations=0')) * 0.000001;
                  $('#total_received_btc').html(total_received_btc);



RE: Convert something loaded from website to an int and multiply - Nachfolger - Mar 1, 2018

(Mar 1, 2018 02:29 PM)Kwast Wrote:  Tried this thing, wont work:
Code
                 var total_received_btc = parseInt(load('https://blockchain.info/q/addressbalance/' + '1EzwoHtiXB4iFwedPr49iywjZn2nnekhoj' + '?confirmations=0')) * 0.000001;
                 $('#total_received_btc').html(total_received_btc);
What even are you doing. I just told you how to do it.


RE: Convert something loaded from website to an int and multiply - Konstantinos - Mar 1, 2018

(Mar 1, 2018 02:29 PM)Nachfolger Wrote:  What the fuck are you doing. I just told you how to do it.

Sorry, I forgot to check your edited post and edit my own as well, your code worked, thanks 🤝