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

Unified Diff: third_party/pkg/angular/lib/filter/number.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/number.dart
diff --git a/third_party/pkg/angular/lib/filter/number.dart b/third_party/pkg/angular/lib/filter/number.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e778d77707a3957513305c21c4ab35099d004128
--- /dev/null
+++ b/third_party/pkg/angular/lib/filter/number.dart
@@ -0,0 +1,43 @@
+part of angular.filter;
+
+/**
+ * Formats a number as text.
+ *
+ * If the input is not a number an empty string is returned.
+ *
+ *
+ * Usage:
+ *
+ * {{ number_expression | number[:fractionSize] }}
+ *
+ */
+@NgFilter(name:'number')
+class NumberFilter {
+
+ Map<num, NumberFormat> nfs = new Map<num, NumberFormat>();
+
+ /**
+ * [value]: the value to format
+ *
+ * [fractionSize]: Number of decimal places to round the number to. If this
+ * is not provided then the fraction size is computed from the current
+ * locale's number formatting pattern. In the case of the default locale,
+ * it will be 3.
+ */
+ call(value, [fractionSize = null]) {
+ if (value is String) value = double.parse(value);
+ if (!(value is num)) return value;
+ if (value.isNaN) return '';
+ var nf = nfs[fractionSize];
+ if (nf == null) {
+ nf = new NumberFormat();
+ nf.maximumIntegerDigits = 9;
+ if (fractionSize != null) {
+ nf.minimumFractionDigits = fractionSize;
+ nf.maximumFractionDigits = fractionSize;
+ }
+ nfs[fractionSize] = nf;
+ }
+ return nf.format(value);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698