We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 50c0bf6 commit c375571Copy full SHA for c375571
pkg/_pub_shared/lib/format/number_format.dart
@@ -15,6 +15,19 @@ String formatWithSuffix(int value) {
15
}
16
17
18
+String formatWithThousandSeperators(int value) {
19
+ final reversed = value.toString().split('').reversed.toList();
20
+ final buffer = StringBuffer();
21
+ for (int j = 0; j < reversed.length; j++) {
22
+ if (j > 0 && j % 3 == 0) {
23
+ buffer.write(',');
24
+ }
25
+ buffer.write(reversed[j]);
26
27
+
28
+ return buffer.toString().split('').reversed.join();
29
+}
30
31
String _toFixed(int value, int d) {
32
return (((value * 10) ~/ d) / 10).toStringAsFixed(1);
33
pkg/_pub_shared/test/format/number_format_test.dart
@@ -66,4 +66,18 @@ void main() {
66
expect(formatWith3SignificantDigits(19000000000),
67
(value: '19.0', suffix: 'B'));
68
});
69
70
+ test('Number with thousand seperators', () {
71
+ // expect(formatWithThousandSeperators(1), '1');
72
+ expect(formatWithThousandSeperators(10), '10');
73
+ expect(formatWithThousandSeperators(100), '100');
74
+ expect(formatWithThousandSeperators(1000), '1,000');
75
+ expect(formatWithThousandSeperators(10000), '10,000');
76
+ expect(formatWithThousandSeperators(100000), '100,000');
77
+ expect(formatWithThousandSeperators(1000000), '1,000,000');
78
+ expect(formatWithThousandSeperators(10000000), '10,000,000');
79
+ expect(formatWithThousandSeperators(100000000), '100,000,000');
80
+ expect(formatWithThousandSeperators(1000000000), '1,000,000,000');
81
+ expect(formatWithThousandSeperators(10000000000), '10,000,000,000');
82
+ });
83
pkg/web_app/lib/src/widget/weekly_sparkline/widget.dart
@@ -1,6 +1,7 @@
1
import 'dart:math';
2
3
import 'package:_pub_shared/format/encoding.dart';
4
+import 'package:_pub_shared/format/number_format.dart';
5
import 'package:intl/intl.dart';
6
import 'package:web/web.dart';
7
@@ -146,7 +147,7 @@ void drawChart(Element svg, HTMLDivElement toolTip, HTMLDivElement chartSubText,
146
147
final coords = computeCoordinates(selectedDay.date, selectedDay.downloads);
148
sparklineSpot.setAttribute('cy', '${coords.$2}');
149
sparklineCursor.setAttribute('transform', 'translate(${coords.$1}, 0)');
- toolTip.text = '${NumberFormat('#,###').format(selectedDay.downloads)}';
150
+ toolTip.text = '${formatWithThousandSeperators(selectedDay.downloads)}';
151
152
final startDate = selectedDay.date.subtract(Duration(days: 7));
153
chartSubText.text =
0 commit comments