Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Unified Diff: third_party/pkg/angular/lib/filter/currency.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/filter/currency.dart
diff --git a/third_party/pkg/angular/lib/filter/currency.dart b/third_party/pkg/angular/lib/filter/currency.dart
new file mode 100644
index 0000000000000000000000000000000000000000..459fe34e35a9f2d35fc05211ae45add492607e5d
--- /dev/null
+++ b/third_party/pkg/angular/lib/filter/currency.dart
@@ -0,0 +1,44 @@
+part of angular.filter;
+
+/**
+ * Formats a number as a currency (ie $1,234.56). When no currency symbol is
+ * provided, '$' used.
+ *
+ *
+ * Usage:
+ *
+ * {{ number_expression | number[:fractionSize] }}
+ *
+ */
+@NgFilter(name:'currency')
+class CurrencyFilter {
+
+ NumberFormat nf = new NumberFormat();
+
+ CurrencyFilter() {
+ nf.minimumFractionDigits = 2;
+ nf.maximumFractionDigits = 2;
+ }
+
+ /**
+ * [value]: the value to format
+ *
+ * [symbol]: Symbol to use.
+ *
+ * [leading]: Symbol should be placed in front of the number
+ */
+ call(value, [symbol = r'$', leading = true]) {
+ if (value is String) value = double.parse(value);
+ if (!(value is num)) return value;
+ if (value.isNaN) return '';
+ var neg = value < 0;
+ if (neg) value = -value;
+ var before = neg ? '(' : '';
+ var after = neg ? ')' : '';
+ if (leading) {
+ return '$before$symbol${nf.format(value)}$after';
+ } else {
+ return '$before${nf.format(value)}$symbol$after';
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698