Jump to content

Is there a way to convert Bitcoin to Satoshie and vice versa?


imgrooot

Recommended Posts

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));

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 years later...

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 by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.