Reputation: 1674
I'm using the java implementation of Bitcoin RPC client.
When I'm calling the createRawTransaction
with int type the raw transaction created as expected:
BitcoindRpcClient.TxOutput txOut1 = new BitcoindRpcClient.BasicTxOutput(issuerAddress,
new BigDecimal(1));
When I'm trying to use double value instead of int:
BitcoindRpcClient.TxOutput txOut1 = new BitcoindRpcClient.BasicTxOutput(issuerAddress,
new BigDecimal(1.2));
I'm receiving this error: invalid amount
.
When I'm trying it by using bitcoin-cli
, it works as expected.
NOTE: I;m working on local testnet blockchain
Upvotes: 1
Views: 260
Reputation: 14671
The output of:
System.out.println(new BigDecimal(1.2));
System.out.println(BigDecimal.valueOf(1.2));
Is:
1.1999999999999999555910790149937383830547332763671875
1.2
So the short answer is to use the preferred way to convert a double: BigDecimal.valueOf(1.2)
The long answer is that floatting numbers are complicated and double
is an approximation for 1.2
Upvotes: 1