add explanatory example for need of Unit

This commit is contained in:
Manuel Araoz 2015-04-06 16:30:25 -03:00
parent 65282dc1b0
commit 5664dac015
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. 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 ## 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. 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.