Explorar o código

fix #347 currency filter with string values

Evan You %!s(int64=12) %!d(string=hai) anos
pai
achega
738a80ef23
Modificáronse 2 ficheiros con 8 adicións e 0 borrados
  1. 1 0
      src/filters.js
  2. 7 0
      test/unit/specs/filters.js

+ 1 - 0
src/filters.js

@@ -35,6 +35,7 @@ filters.lowercase = function (value) {
  *  12345 => $12,345.00
  */
 filters.currency = function (value, sign) {
+    value = parseFloat(value)
     if (!value && value !== 0) return ''
     sign = sign || '$'
     var s = Math.floor(value).toString(),

+ 7 - 0
test/unit/specs/filters.js

@@ -98,6 +98,13 @@ describe('Filters', function () {
             assert.strictEqual(res4, '$0.00')
         })
 
+        it('should cast strings into float', function () {
+            var res1 = filter('fesf'),
+                res2 = filter('0.24')
+            assert.strictEqual(res1, '')
+            assert.strictEqual(res2, '$0.24')
+        })
+
     })
 
     describe('key', function () {