From 168d87185ce5a3d7a9e418ebe0f5cda5e29726ad Mon Sep 17 00:00:00 2001 From: Yemel Jardi Date: Thu, 25 Dec 2014 19:14:06 -0300 Subject: [PATCH] Update bitcore guide --- docs/guide/unit.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/guide/unit.md b/docs/guide/unit.md index b09640f..10de6a5 100644 --- a/docs/guide/unit.md +++ b/docs/guide/unit.md @@ -61,3 +61,19 @@ value = Unit.fromBTC(amount).mBTC; value = Unit.fromBTC(amount).bits; value = Unit.fromBTC(amount).satoshis; ``` + +## Using a fiat currency + +The unit class also provides a convenient alternative to create an instance from a fiat amount and the corresponding BTC/fiat exchange rate. Any unit instance can be converted to a fiat amount by providing the current exchange rate. Check the example below: + +```javascript +var unit, fiat; +var amount = 100; +var exchangeRate = 350; + +unit = new Unit(amount, exchangeRate); +unit = Unit.fromFiat(amount, exchangeRate); + +fiat = Unit.fromBits(amount).toFiat(exchangeRate); +fiat = Unit.fromBits(amount).to(exchangeRate); +```