imgrooot Posted January 9, 2019 Share Posted January 9, 2019 Apparently it's bad to use floats when working with bitcoin. But the API i'm using doesn't really give an option to convert Bitcoin to Satoshie or vice versa. https://www.block.io/api/simple/php So I'm trying to figure out a way to do that function with PHP. Here is the code I found that converts from Satoshie to Bitcoin. My question is, how do I convert from Bitcoin to Satoshie. function convertToBTCFromSatoshi($value) { $BTC = $value / 100000000 ; return $BTC; } function formatBTC($value) { $value = sprintf('%.8f', $value); $value = rtrim($value, '0') . ' BTC'; return $value; } echo formatBTC(convertToBTCFromSatoshi(5000)); Quote Link to comment https://forums.phpfreaks.com/topic/308128-is-there-a-way-to-convert-bitcoin-to-satoshie-and-vice-versa/ Share on other sites More sharing options...
requinix Posted January 9, 2019 Share Posted January 9, 2019 This is what converts. function convertToBTCFromSatoshi($value) { $BTC = $value / 100000000 ; return $BTC; } Do I need to say anything more? Quote Link to comment https://forums.phpfreaks.com/topic/308128-is-there-a-way-to-convert-bitcoin-to-satoshie-and-vice-versa/#findComment-1563397 Share on other sites More sharing options...
ginerjm Posted January 9, 2019 Share Posted January 9, 2019 I may regret asking this but - are you sure about that? Is going from a to b involves division, wouldn't the reverse involve multiplication? Quote Link to comment https://forums.phpfreaks.com/topic/308128-is-there-a-way-to-convert-bitcoin-to-satoshie-and-vice-versa/#findComment-1563398 Share on other sites More sharing options...
imgrooot Posted January 10, 2019 Author Share Posted January 10, 2019 2 hours ago, requinix said: This is what converts. function convertToBTCFromSatoshi($value) { $BTC = $value / 100000000 ; return $BTC; } Do I need to say anything more? 2 hours ago, ginerjm said: I may regret asking this but - are you sure about that? Is going from a to b involves division, wouldn't the reverse involve multiplication? Correct, the multiplication would do the reverse. Like this. function convertToSatoshi($value) { $SAT = $value * 100000000 ; return $SAT; } I was more worried about reversing the decimal part of the 2nd function, but I just realized that it's not needed to convert to Satoshie. Quote Link to comment https://forums.phpfreaks.com/topic/308128-is-there-a-way-to-convert-bitcoin-to-satoshie-and-vice-versa/#findComment-1563400 Share on other sites More sharing options...
Cor4Flez Posted February 24, 2021 Share Posted February 24, 2021 (edited) It all depends on how exactly you want to convert this currency and whether you want to automate this process. If you manually do this, then you can use cryptocurrency converters, fortunately they are very popular now. The main thing is to choose exactly the converter that will have real and positive reviews, otherwise you risk being deceived. I personally use this method, but I do it in order to convert the real money that I earn thanks to [spammy link deleted] in cryptocurrency (I think you should not explain why I do this). It is not very difficult to find a really high-quality service that provides such services, but again, you need to be very careful when choosing, as the future of your money depends on it! Edited February 24, 2021 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/308128-is-there-a-way-to-convert-bitcoin-to-satoshie-and-vice-versa/#findComment-1584765 Share on other sites More sharing options...
Barand Posted February 24, 2021 Share Posted February 24, 2021 @Cor4Flez Let sleeping posts lie. This one is two years old. Quote Link to comment https://forums.phpfreaks.com/topic/308128-is-there-a-way-to-convert-bitcoin-to-satoshie-and-vice-versa/#findComment-1584766 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.