2.0.0 • Published 7 years ago

toformat v2.0.0

Weekly downloads
8,537
License
MIT
Repository
github
Last release
7 years ago

toFormat

Adds a toFormat instance method to big.js or decimal.js.

Install

Node.js

$ npm install toformat

Browser

<script src='path/to/big.js'></script>
<script src='path/to/toFormat.js'></script>

Use

Node.js

Big = require('big')
Big = require('toformat')(Big)

x = new Big(9876.54321)
x.toFormat(2)                       // '9,876.54'

// Three different ways of setting a formatting property
Big.format.decimalSeparator = ','
x.format.groupSeparator: ' '
x.toFormat(1, { groupSize: 2 })    // '98 76,5'

Browser

toFormat(Big)
x = new Big(9876.54321)
x.toFormat(2)                      // '9,876.54'

Further examples:

// The format object added to the Decimal constructor by this library.
Decimal.format = {
  decimalSeparator: '.',
  groupSeparator: ',',
  groupSize: 3,
  secondaryGroupSize: 0,
  fractionGroupSeparator: '',
  fractionGroupSize : 0
}

x.toFormat()                        // 123,456,789.987654321
x.toFormat(2, 1)                    // 123,456,789.98

// Add a format object to a Decimal instance.
x.format = {
  decimalSeparator: ',',
  groupSeparator: '',
}

x.toFormat()                       // 123456789,987654321

format = {
  decimalSeparator: '.',
  groupSeparator: ' ',
  groupSize: 3,
  fractionGroupSeparator: ' ',
  fractionGroupSize : 5
}

// Pass a format object to the method call.
x.toFormat(format)                 // 123 456 789.98765 4321
x.toFormat(4, format)              // 123 456 789.9877
x.toFormat(2, 1, format)           // 123 456 789.98

Test

$ npm test

Licence

MIT

confidence-sdkconfidence-sdk-v13@conedex/conedex-sdk-core@benboba790111/uniswap-v2-sdk@trebodex/sdk@trebodex/trebodex-sdk-core@nekomeowww/uniscam-sdk@nekomeowww/uniswap-earndefi-sdk@muhammadwajidshahid/swap-sdk@exchange-one/sdk@exchange-one/sdk-core@harmony-swoop/sdk@linbingdefi/sdktttswap-sdk@magic-finance-cards/magic-sdk@roc-protocol/roc-sdkmy-deerfi-sdk@crisog/uniswap-sdk@batsoft/swappornswap-sdk@pornswap/pornswap-sdkheco-sdk@twswap/sdkcustomsdkttcryptoswap-sdk-core@thismr/bitmindtest-sdk1@aliumswap/sdkgreenteaswap-libs-sdk@thecompounder/sdk@theanthill/pancakeswap-libs-sdk@shibance/sdkdepth-swap@freeswap/sdk@zetaswap/sdk@zettaswap/sdk@sonicswap/sdk-devdungnv-sdkztopiauniswaptest@bscsswap/sdk@beswap/sdkcortex-test-sdkfreeswap-sdkfreeswap-sdk2@manekiswap/manekiswap-sdkliger-sdkinmergerswap-sdkokexshibaswap-sdksphinxsjc-sdkbimswap-sdkhayek-uniswap-sdk@avacadodefi/sdkv1cronswap-sdkalpes-sdk@dahuswap/sdkapeswap-sdk@wanwantip/jdi-sdk@dexorzo/sdk@heshiswap/sdk-coremathswap-sdkinmerger-ropsten-sdk@ashalfarhan/legionswap-sdk-testnet@duythao_bacoor/sdk@trader-b0b/sdk@ladarken/sdk@ladarken/sdktestpawsswap-sdkpolygon-moonwalkerswap-sdkhuobiswapsdkrcpswaptestgolswap-sdk@qdexgo/bscsdk@qdexgo/ethsdk@qdexgo/matic-sdk@jjf7/gol-sdk@alayaswap/sdk-core@circusdao/clownswap-v2-sdk@circusdao/juggler-v2-sdk@cherryswap/sdk@fathomswap/sdkdotoracle-sdk@intercroneswap/sdk-core@kdefi/sdk@steban1/bchswap-sdk@koingfu.com/rskswap-sdk@koingfu.com/v2-swap-avax@koingfu.com/v2-swap-bsc@koingfu.com/v2-swap-polygon@koingfu.com/v2-swap-sbch@koingfu.com/v2-swap-sbch-testnetcheektswap-sdkastra-swap-sdkbscktswap-sdkbbscktswap-sdktattooswapsdksouvla-swap-core-sdkleekswap-sdkleekswap-test-sdkmatic-test-sdkmeowswap-test-sdk@fantasywar/sdk
2.0.0

7 years ago

1.0.0

9 years ago