to-percentage-by
v1.1.0
Published
Convert a Float number to percentage with rounding, ceiling or flooring.
Downloads
8
Maintainers
Readme
to-percentage-by
Convert a Float number to percentage with rounding, ceiling or flooring.
Installation
$ npm install to-percentage-by --save
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
).