1.1.0 • Published 8 years ago

to-percentage-by v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

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

ValueDefaultNotes
digits2The number of digits to appear after the decimal point
methodMath.roundCould be Math.round, Math.ceil or Math.floor method
floatThe 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

1.1.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.0

8 years ago

1.0.1

8 years ago