Merge pull request #1179 from maraoz/unit/docs

add explanatory example for need of Unit
This commit is contained in:
Braydon Fuller 2015-04-06 22:35:50 -04:00
commit 8ebf2e6f1f
1 changed files with 10 additions and 0 deletions

View File

@ -8,6 +8,16 @@ description: Utility to easily convert between bitcoin units.
Unit is a utility for handling and converting bitcoin units. We strongly recommend to always use satoshis to represent amount inside your application and only convert them to other units in the front-end.
To understand the need of using the `Unit` class when dealing with unit conversions, see this example:
```
> 81.99 * 100000 // wrong
8198999.999999999
> var bitcore = require('bitcore');
> var Unit = bitcore.Unit;
> Unit.fromMilis(81.99).toSatoshis() // correct
8199000
```
## Supported units
The supported units are BTC, mBTC, bits (micro BTCs, uBTC) and satoshis. The codes for each unit can be found as members of the Unit class.