File tree 3 files changed +36
-0
lines changed
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,13 @@ <h3>limitFrom(1,2)</h3>
54
54
55
55
< h3 > wordcount</ h3 >
56
56
{{'Hello World' | wordcount}}
57
+
58
+ < h3 > round</ h3 >
59
+ {{ 45.35 | round }}
60
+
61
+ < h3 > round(1, 'floor')</ h3 >
62
+ {{ 45.35 | round(1, 'floor') }}
63
+
57
64
</ template >
58
65
< script >
59
66
var template = document . getElementById ( 'view' ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Round a number by a specific precision or method
3
+ * @param {integer } val
4
+ * @param {integer } precision
5
+ * @param {string } method
6
+ * @return {string }
7
+ */
8
+ PolymerExpressions . prototype . round = function ( val , precision , method ) {
9
+ precision = precision || 0 ;
10
+ var factor = Math . pow ( 10 , precision ) ;
11
+ var rounder ;
12
+
13
+ if ( method == 'ceil' ) {
14
+ rounder = Math . ceil ;
15
+ } else if ( method == 'floor' ) {
16
+ rounder = Math . floor ;
17
+ } else {
18
+ rounder = Math . round ;
19
+ }
20
+
21
+ return rounder ( val * factor ) / factor ;
22
+ } ;
Original file line number Diff line number Diff line change 8
8
< script src ="filter-replace.js "> </ script >
9
9
< script src ="filter-startsWith.js "> </ script >
10
10
< script src ="filter-wordcount.js "> </ script >
11
+ < script src ="filter-round.js "> </ script >
11
12
12
13
<!--
13
14
A collection of Polymer filters for formatting values of expressions for display to users
56
57
57
58
{{'Hello World' | wordcount}}
58
59
60
+ ####Rounding
61
+
62
+ {{ 45.35 | round }}
63
+
64
+ {{ 45.35 | round(1, 'floor') }}
65
+
59
66
@element polymer-filters
60
67
@blurb A collection of Polymer filters for formatting values of expressions for display to users
61
68
@homepage http://addyosmani.github.io/polymer-filters
You can’t perform that action at this time.
0 commit comments