From 5664dac01528913a0522188b8f22b98e2f9f356f Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 6 Apr 2015 16:30:25 -0300 Subject: [PATCH] add explanatory example for need of Unit --- docs/unit.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/unit.md b/docs/unit.md index dd03c89cb..7d3db82cc 100644 --- a/docs/unit.md +++ b/docs/unit.md @@ -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.