okx / js-wallet-sdk

Multi-chain typescript signature sdk, supports bitcoin, ethereum, solana, cosmos, etc.
https://okx.github.io/js-wallet-sdk/#/
MIT License
197 stars 68 forks source link

The accuracy of floating-point operations in 'TypeScript' #116

Closed Gu-code99 closed 1 week ago

Gu-code99 commented 1 month ago

module: coin-bitcoin example: txBuild.calculateTxSize() ->return { inputAmount, outputAmount, virtualSize, txHex };

virtualSize type is 'Number'(In TypeScript) The type of feePerB is also 'Number' estimateBtcFee = virtualSize * feePerB,When fee is a decimal, there may be precision errors in floating-point operations If virtualSize =350,feePerB=2.2, The actual result should be 770, but the result in ts is 770.00000000001

luyishisi commented 4 weeks ago

Thank you for your feedback, we will arrange for optimization