GithubHelp home page GithubHelp logo

satoshi-bitcoin's Introduction

satoshi-bitcoin

🧪 npm test npm version

npm module to convert between Satoshi and Bitcoin with lightweight precision.


The Problem

The problem


Install

npm install --save satoshi-bitcoin

# OR

yarn add satoshi-bitcoin

Usage

Node.js

var sb = require("satoshi-bitcoin");

sb.toSatoshi(1);
//=>100000000

sb.toBitcoin(100000000);
//=>1

Web

<!-- package injected as "sb" -->
<script src="https://rawgit.com/dawsonbotsford/satoshi-bitcoin/master/index.bundle.js"></script>
<script>
  console.log("One Satoshi equals " + sb.toBitcoin(1) + " Bitcoin");
</script>

Or download it with npm install --save satoshi-bitcoin and reference it as:

<script src="node_modules/satoshi-bitcoin/index.bundle.js"></script>

Error Handling

try {
  sb.toSatoshi(false); //Throws TypeError
} catch (err) {
  console.log(err);
}

API

sb.toSatoshi(number || string) sb.toBitcoin(number || string)

Read more on the Wiki


FAQ

  • What is a Satoshi?

    • Satoshi is to Bitcoin as pennies are to the dollar. Except that there are 100,000,000 Satoshi in one Bitcoin.
  • Why do I need a module when I can just divide or multiply by 100,000,000?

    • See here - Floating point errors are a problem. So satoshi-bitcoin uses a tiny bignum library (big.js) to ensure accurate conversions!

Tests

npm test

License

MIT © Dawson Botsford

satoshi-bitcoin's People

Contributors

dawsbot avatar dependabot[bot] avatar greenkeeperio-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

satoshi-bitcoin's Issues

Provide motivation

  • Move FAQ higher up in README
  • Show before and after library usage (to emphasize floating point errors)

fix problem

4.6*100000000
"459999999.99999994"
(4.6*100000000).toFixed()
"460000000"

Bring eslint into repo

  • Move .eslint into repo
  • Remove link from readme to eslint
  • Add linting tests to test suite

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.