This repository was archived by the owner on Oct 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ def _escape_value(value):
113
113
return str (value ) + 'i'
114
114
115
115
if _is_float (value ):
116
- return repr (value )
116
+ return repr (float ( value ) )
117
117
118
118
return str (value )
119
119
Original file line number Diff line number Diff line change 6
6
from __future__ import print_function
7
7
from __future__ import unicode_literals
8
8
9
- from datetime import datetime
10
9
import unittest
11
- from pytz import UTC , timezone
12
10
11
+ from datetime import datetime
12
+ from decimal import Decimal
13
+
14
+ from pytz import UTC , timezone
13
15
from influxdb import line_protocol
14
16
15
17
@@ -166,3 +168,20 @@ def test_float_with_long_decimal_fraction(self):
166
168
line_protocol .make_lines (data ),
167
169
'test float_val=1.0000000000000009\n '
168
170
)
171
+
172
+ def test_float_with_long_decimal_fraction_as_type_decimal (self ):
173
+ """Ensure precision is preserved when casting Decimal into strings."""
174
+ data = {
175
+ "points" : [
176
+ {
177
+ "measurement" : "test" ,
178
+ "fields" : {
179
+ "float_val" : Decimal (1.0000000000000009 ),
180
+ }
181
+ }
182
+ ]
183
+ }
184
+ self .assertEqual (
185
+ line_protocol .make_lines (data ),
186
+ 'test float_val=1.0000000000000009\n '
187
+ )
You can’t perform that action at this time.
0 commit comments