Repository: genjidb/genji
Pull request #246 (2020-10-09 17:14:34)

Display doubles with a decimal point
This pull request is for #237 

codecov-io: # [Codecov](https://codecov.io/gh/genjidb/genji/pull/246?src=pr&el=h1) Report
> Merging [#246](https://codecov.io/gh/genjidb/genji/pull/246?src=pr&el=desc) into [master](https://codecov.io/gh/genjidb/genji/commit/5a3cc7be3783457ed96050d7e7c1369efbaadafb?el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/genjidb/genji/pull/246/graphs/tree.svg?width=650&height=150&src=pr&token=nwR1GpvtyH)](https://codecov.io/gh/genjidb/genji/pull/246?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #246      +/-   ##
==========================================
+ Coverage   61.34%   61.35%   +0.01%     
==========================================
  Files          68       68              
  Lines        6327     6324       -3     
==========================================
- Hits         3881     3880       -1     
+ Misses       1933     1932       -1     
+ Partials      513      512       -1     
```


| [Impacted Files](https://codecov.io/gh/genjidb/genji/pull/246?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [document/value.go](https://codecov.io/gh/genjidb/genji/pull/246/diff?src=pr&el=tree#diff-ZG9jdW1lbnQvdmFsdWUuZ28=) | `73.43% <100.00%> (+0.43%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/genjidb/genji/pull/246?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/genjidb/genji/pull/246?src=pr&el=footer). Last update [5a3cc7b...c60021c](https://codecov.io/gh/genjidb/genji/pull/246?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/document/value.go b/document/value.go
index 47e9aefb..1d80ebff 100644
--- a/document/value.go
+++ b/document/value.go
@@ -250,15 +250,10 @@ func (v Value) MarshalJSON() ([]byte, error) {
 		return strconv.AppendInt(nil, v.V.(int64), 10), nil
 	case DoubleValue:
 		f := v.V.(float64)
-		abs := math.Abs(f)
-		fmt := byte('f')
-		if abs != 0 {
-			if abs < 1e-6 || abs >= 1e21 {
-				fmt = 'e'
-			}
+		if f == float64(int(f)) {
+			return strconv.AppendFloat(nil, f, 'f', 1, 64), nil
 		}
-
-		return strconv.AppendFloat(nil, v.V.(float64), fmt, -1, 64), nil
+		return strconv.AppendFloat(nil, f, 'f', -1, 64), nil
 	case TextValue:
 		return []byte(strconv.Quote(v.V.(string))), nil
 	case BlobValue:


Test patch:
diff --git a/document/value_test.go b/document/value_test.go
index c0a08a3b..a6fcc514 100644
--- a/document/value_test.go
+++ b/document/value_test.go
@@ -21,6 +21,7 @@ func TestValueString(t *testing.T) {
 		{"bool", document.NewBoolValue(true), "true"},
 		{"int", document.NewIntegerValue(10), "10"},
 		{"double", document.NewDoubleValue(10.1), "10.1"},
+		{"double", document.NewDoubleValue(10), "10.0"},
 		{"document", document.NewDocumentValue(document.NewFieldBuffer().Add("a", document.NewIntegerValue(10))), "{\"a\": 10}"},
 		{"array", document.NewArrayValue(document.NewValueBuffer(document.NewIntegerValue(10))), "[10]"},
 	}