UNPKG
to-percentage
Version:
latest (1.0.0)
1.0.0
0.0.1
Convert floats to string percentages.
github.com/johnotander/to-percentage
johnotander/to-percentage
to-percentage
/
index.js
11 lines
(8 loc)
•
256 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
'use strict'
module
.
exports
=
function
toPercentage
(
value, numDecimals
) {
if
(
typeof
value !==
'number'
) {
throw
new
TypeError
(
'to-percentage expected a number'
) } value *=
100
return
value.
toFixed
(value %
1
===
0
?
0
: numDecimals) +
'%'
}