Showing
2 changed files
with
15 additions
and
4 deletions
@@ -72,7 +72,18 @@ class PdfNum extends PdfDataType { | @@ -72,7 +72,18 @@ class PdfNum extends PdfDataType { | ||
72 | if (value is int) { | 72 | if (value is int) { |
73 | s.putString(value.toInt().toString()); | 73 | s.putString(value.toInt().toString()); |
74 | } else { | 74 | } else { |
75 | - s.putString(value.toStringAsFixed(precision)); | 75 | + var r = value.toStringAsFixed(precision); |
76 | + if (r.contains('.')) { | ||
77 | + var n = r.length - 1; | ||
78 | + while (r[n] == '0') { | ||
79 | + n--; | ||
80 | + } | ||
81 | + if (r[n] == '.') { | ||
82 | + n--; | ||
83 | + } | ||
84 | + r = r.substring(0, n + 1); | ||
85 | + } | ||
86 | + s.putString(r); | ||
76 | } | 87 | } |
77 | } | 88 | } |
78 | } | 89 | } |
@@ -27,9 +27,9 @@ void main() { | @@ -27,9 +27,9 @@ void main() { | ||
27 | 27 | ||
28 | test('PdfDataTypes Num', () { | 28 | test('PdfDataTypes Num', () { |
29 | expect(const PdfNum(0).toString(), '0'); | 29 | expect(const PdfNum(0).toString(), '0'); |
30 | - expect(const PdfNum(.5).toString(), '0.50000'); | 30 | + expect(const PdfNum(.5).toString(), '0.5'); |
31 | expect(const PdfNum(50).toString(), '50'); | 31 | expect(const PdfNum(50).toString(), '50'); |
32 | - expect(const PdfNum(50.1).toString(), '50.10000'); | 32 | + expect(const PdfNum(50.1).toString(), '50.1'); |
33 | }); | 33 | }); |
34 | 34 | ||
35 | test('PdfDataTypes String', () { | 35 | test('PdfDataTypes String', () { |
@@ -84,7 +84,7 @@ void main() { | @@ -84,7 +84,7 @@ void main() { | ||
84 | PdfArray(), | 84 | PdfArray(), |
85 | PdfDict(), | 85 | PdfDict(), |
86 | ]).toString(), | 86 | ]).toString(), |
87 | - '[/Name/Other false 2.50000 null(þÿ\x00h\x00e\x00l\x01B\x00o)[]<<>>]', | 87 | + '[/Name/Other false 2.5 null(þÿ\x00h\x00e\x00l\x01B\x00o)[]<<>>]', |
88 | ); | 88 | ); |
89 | }); | 89 | }); |
90 | 90 |
-
Please register or login to post a comment