Skip to content

Commit

Permalink
fix: Use G17 format for doubles
Browse files Browse the repository at this point in the history
fixes: #408
  • Loading branch information
powersj committed Dec 5, 2022
1 parent 9c54998 commit 1f37e06
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 4.9.0 [unreleased]

### Bug Fixes
1. [#408](https://github.com/influxdata/influxdb-client-csharp/issues/408): Conversion of double to string can result in a loss of precision

### Dependencies
Update dependencies:

Expand Down
8 changes: 6 additions & 2 deletions Client/Writes/PointData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,14 @@ private bool AppendFields(StringBuilder sb)
EscapeKey(sb, key);
sb.Append('=');

if (value is double || value is float)
if (value is float)
{
sb.Append(((IConvertible)value).ToString(CultureInfo.InvariantCulture));
}
else if (value is double)
{
sb.Append(((IConvertible)value).ToString("G17"));
}
else if (value is uint || value is ulong || value is ushort)
{
sb.Append(((IConvertible)value).ToString(CultureInfo.InvariantCulture));
Expand Down Expand Up @@ -713,4 +717,4 @@ public override int GetHashCode()
return !(left == right);
}
}
}
}

0 comments on commit 1f37e06

Please sign in to comment.