Skip to content

Commit 701ef03

Browse files
authored
Revert "fix: use g17 format for doubles (#434)" (#467)
This reverts commit c4b64ae.
1 parent c611192 commit 701ef03

File tree

4 files changed

+7
-28
lines changed

4 files changed

+7
-28
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 4.11.0 [unreleased]
22

3+
### Bug Fixes
4+
- Revert [#408] conversion of double to string can result in a loss of precision
5+
36
## 4.10.0 [2023-01-26]
47

58
### Bug Fixes

Client.Test/MeasurementMapperTest.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ public void ColumnWithoutName()
5757

5858
var lineProtocol = _mapper.ToPoint(poco, WritePrecision.S).ToLineProtocol();
5959

60-
Assert.AreEqual(
61-
"poco,tag=tag\\ val value=15.444000000000001,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000",
60+
Assert.AreEqual("poco,tag=tag\\ val value=15.444,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000",
6261
lineProtocol);
6362
}
6463

@@ -112,8 +111,7 @@ public void MeasurementProperty()
112111

113112
var lineProtocol = _mapper.ToPoint(poco, WritePrecision.S).ToLineProtocol();
114113

115-
Assert.AreEqual(
116-
"poco,tag=tag\\ val value=15.444000000000001,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000",
114+
Assert.AreEqual("poco,tag=tag\\ val value=15.444,ValueWithEmptyName=25,ValueWithoutDefaultName=20i 864000",
117115
lineProtocol);
118116
}
119117

Client.Test/PointDataTest.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,7 @@ public void FieldTypes()
149149

150150
var expected =
151151
"h2o,location=europe boolean=false,byte=9i,decimal=25.6,double=250.69,float=35,integer=7i,long=1i," +
152-
"point=13.300000000000001,sbyte=12i,short=8i,string=\"string value\",uint=11u,ulong=10u,ushort=13u";
153-
154-
Assert.AreEqual(expected, point.ToLineProtocol());
155-
}
156-
157-
[Test]
158-
public void DoubleFormat()
159-
{
160-
var point = PointData.Measurement("sensor")
161-
.Field("double", 250.69D)
162-
.Field("double15", 15.333333333333333D)
163-
.Field("double16", 16.3333333333333333D)
164-
.Field("double17", 17.33333333333333333D)
165-
.Field("example", 459.29587181322927);
166-
167-
var expected =
168-
"sensor double=250.69,double15=15.333333333333332,double16=16.333333333333332," +
169-
"double17=17.333333333333332,example=459.29587181322927";
152+
"point=13.3,sbyte=12i,short=8i,string=\"string value\",uint=11u,ulong=10u,ushort=13u";
170153

171154
Assert.AreEqual(expected, point.ToLineProtocol());
172155
}

Client/Writes/PointData.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,10 @@ private bool AppendFields(StringBuilder sb)
472472
EscapeKey(sb, key);
473473
sb.Append('=');
474474

475-
if (value is float)
475+
if (value is double || value is float)
476476
{
477477
sb.Append(((IConvertible)value).ToString(CultureInfo.InvariantCulture));
478478
}
479-
else if (value is double)
480-
{
481-
var valueStr = ((double)value).ToString("G17", CultureInfo.InvariantCulture);
482-
sb.Append((IConvertible)valueStr);
483-
}
484479
else if (value is uint || value is ulong || value is ushort)
485480
{
486481
sb.Append(((IConvertible)value).ToString(CultureInfo.InvariantCulture));

0 commit comments

Comments
 (0)