to-percentage-by

1.1.0 • Public • Published

to-percentage-by

Convert a Float number to percentage with rounding, ceiling or flooring.

Travis Codecov Status npm package npm downloads license

Dependency Status devDependency Status peerDependency Status

Installation

$ npm install to-percentage-by --save

Quick DEMO on tonicdev

Usage

import {
  default as toPercentageBy,
  toPercentage as defaultToPercentageBy,
} from 'to-percentage-by';
 
// defaultToPercentageBy equals to toPercentageBy()
 
var toPercentage = toPercentageBy();
t.is(toPercentage(0.11111), '11.11%');
t.is(defaultToPercentageBy(0.11111), '11.11%');
 
var toPercentage = toPercentageBy(0);
t.is(toPercentage(0.11111), '11%');
 
var toPercentage = toPercentageBy(2, Math.ceil);
t.is(toPercentage(0.11111), '11.12%');
 
var toPercentage = toPercentageBy(2, Math.floor);
t.is(toPercentage(0.11115), '11.11%');

API

type ToPercentage = (float: number) => string;
 
toPercentageBy(
  ?digits: number,
  ?method: Function,
): ToPercentage

Property

Value Default Notes
digits 2 The number of digits to appear after the decimal point
method Math.round Could be Math.round, Math.ceil or Math.floor method
float The number to be converted.

Test

$ npm run lint
$ npm run test:watch

CONTRIBUTING

  • ⇄ Pull requests and ★ Stars are always welcome.
  • For bugs and feature requests, please create an issue.
  • Pull requests must be accompanied by passing automated tests ($ npm test).

CHANGELOG

LICENSE

MIT: http://michaelhsu.mit-license.org

Package Sidebar

Install

npm i to-percentage-by

Weekly Downloads

0

Version

1.1.0

License

MIT

Last publish

Collaborators

  • evenchange4