I have the following code that converts my satoshi value to a bitcoin value:
private static double satToBtc(long sat){
return sat / Math.pow(10, 8);
}
now I have the following code executing:
double btc = satToBtc(value);
User user = User.getUserByDepositBitcoinAddress(address);
if (user == null) return;
try (Connection connection = MySQL.getConnection();
...
statement.setDouble(3, btc);
...
return;
}
now what is happening is, I am given the satoshi amount of 100,000 which is worth 0.001 (the function returns exactly 0.001
) bitcoin but when I store it in my mysql table it sets the value as: 0.00000001
.
How do I go about fixing this?
EDIT - UPDATED satToBtc
function:
private static BigDecimal satToBtc(long sat){
return new BigDecimal(sat / Math.pow(10, 8));
}