new Unit(amount, code) → {Unit}
Bitcore Unit
Utility for handling and converting bitcoins units. The supported units are BTC, mBTC, bits and satoshis. A unit instance can be created with an amount and a unit code, or alternatively using static methods like {fromBTC}. You can consult for different representation of a unit instance using it's {to} method, the fixed unit methods like {toSatoshis} or alternatively using the unit accessors.
Parameters:
| Name | Type | Description |
|---|---|---|
amount |
Number | The amount to be represented |
code |
String | The unit of the amount |
Returns:
A new instance of an Unit
- Type
- Unit
Example
var sats = Unit.fromBTC(1.3).toSatoshis(); var mili = Unit.fromBits(1.3).to(Unit.mBTC); var btc = new Unit(1.3, Unit.bits).BTC;
Members
-
<static> fromMicros
-
Will return a Unit instance created from an amount in bits
-
toMicros
-
Will return the value represented in bits
Methods
-
<static> fromBTC(amount) → {Unit}
-
Will return a Unit instance created from an amount in BTC
Parameters:
Name Type Description amountNumber The amount in BTC
Returns:
A Unit instance
- Type
- Unit
-
<static> fromJSON(json) → {Unit}
-
Will return a Unit instance created from JSON string or object
Parameters:
Name Type Description jsonString | Object JSON with keys: amount and code
Returns:
A Unit instance
- Type
- Unit
-
<static> fromMilis(amount) → {Unit}
-
Will return a Unit instance created from an amount in mBTC
Parameters:
Name Type Description amountNumber The amount in mBTC
Returns:
A Unit instance
- Type
- Unit
-
<static> fromSatoshis(amount) → {Unit}
-
Will return a Unit instance created from an amount in satoshis
Parameters:
Name Type Description amountNumber The amount in satoshis
Returns:
A Unit instance
- Type
- Unit
-
inspect() → {String}
-
Will return a string formatted for the console
Returns:
the value in satoshis
- Type
- String
-
to(code) → {Number}
-
Will return the value represented in the specified unit
Parameters:
Name Type Description codestring The unit code
Returns:
The converted value
- Type
- Number
-
toBTC() → {Number}
-
Will return the value represented in BTC
Returns:
The value converted to BTC
- Type
- Number
-
toMilis() → {Number}
-
Will return the value represented in mBTC
Returns:
The value converted to mBTC
- Type
- Number
-
toObject() → {Object}
-
Will return a plain object representation of the Unit
Returns:
An object with the keys: amount and code
- Type
- Object
-
toSatoshis() → {Number}
-
Will return the value represented in satoshis
Returns:
The value converted to satoshis
- Type
- Number
-
toString() → {String}
-
Will return a the string representation of the value in satoshis
Returns:
the value in satoshis
- Type
- String