Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

bitcoin: fix value floating point precision issue#336

Open
matthewjablack wants to merge 1 commit into
node-lightning:mainfrom
matthewjablack:fix-value-floating-point-precision
Open

bitcoin: fix value floating point precision issue#336
matthewjablack wants to merge 1 commit into
node-lightning:mainfrom
matthewjablack:fix-value-floating-point-precision

Conversation

@matthewjablack

@matthewjablack matthewjablack commented Nov 23, 2023

Copy link
Copy Markdown
Contributor

Switches Value.fromBitcoin to use Math.round instead of Math.trunc since it can result in off by one sat issues

For example, Value.fromBitcoin(20000000.00000008).bitcoin equals 20000000.00000007 not 20000000.00000008 if using Math.trunc

- Value previously used `Math.trunc` for `fromBitcoin` which can result
  in off by one sat issues
- Switching to using Math.round solves this issue
- Added test which fails using `Math.trunc`
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e9b349b) 93.17% compared to head (37fbf85) 93.17%.

❗ Current head 37fbf85 differs from pull request most recent head d451218. Consider uploading reports for the commit d451218 to get more accurate results

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #336   +/-   ##
=======================================
  Coverage   93.17%   93.17%           
=======================================
  Files         226      226           
  Lines        6271     6271           
  Branches      730      730           
=======================================
  Hits         5843     5843           
  Misses        286      286           
  Partials      142      142           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants