File tree 1 file changed +11
-14
lines changed
1 file changed +11
-14
lines changed Original file line number Diff line number Diff line change 1
1
import util from '../util/index'
2
2
3
3
/**
4
- * 12 => '12%'
5
- * 100 => '100%'
6
- * 1000 => '1000%'
4
+ * 1.2 => '120%'
5
+ * -0.2 => '-20%'
6
+ * 100 => '10000%'
7
+ * 1 => '100%'
7
8
* 0.97 => '97%'
8
9
*
9
10
* @param {Number } value
10
11
* @param {Number } decimals Decimal places (default: 2)
11
12
*/
12
13
function percent ( value , decimals ) {
13
- const globalOptions = ( this && this . percent ) ? this . percent : { }
14
- decimals = util . exist ( decimals ) ? decimals : globalOptions . decimalDigits
15
- decimals = ( typeof decimals !== 'undefined' ) ? decimals : 0
16
- value = value === null || isNaN ( value ) ? 0 : value
17
-
18
- if ( value <= 1 ) {
19
- return `${ ( value * 100 ) . toFixed ( decimals ) } %`
20
- }
21
-
22
- return `${ value . toFixed ( decimals ) } %`
14
+ const globalOptions = this && this . percent ? this . percent : { }
15
+ decimals = util . exist ( decimals ) ? decimals : globalOptions . decimalDigits
16
+ decimals = typeof decimals !== 'undefined' ? decimals : 0
17
+ value = value === null || isNaN ( value ) ? 0 : value
18
+
19
+ return `${ ( value * 100 ) . toFixed ( decimals ) } %`
23
20
}
24
21
25
- export default percent
22
+ export default percent
You can’t perform that action at this time.
0 commit comments