# Float type rounding issues

**URL:** <https://discuss.elastic.co/t/float-type-rounding-issues/321859>\
**Category:** Kibana\
**Created:** [December 22, 2022, 5:51pm UTC](https://discuss.elastic.co/t/float-type-rounding-issues/321859 "2022-12-22T17:51:28Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 23, 2022, 2:00am UTC](https://discuss.elastic.co/t/float-type-rounding-issues/321859/6 "2022-12-23T02:00:51Z")

</div>

(please try not to paste text as images... hard to see, help, debug etc...etc. paste as formatted text)

But YUP You need to use a `double` as the type not `float` as you are exceeding the significant digits of a single precision `float`

Also you are confusing the `_source` (what comes in the source json) and the `fields` what is index stored and showed in the Discover, Visualizations.. etc

Here follow along

What you have now

```auto
PUT discuss-test/
{
  "mappings" : {
  "properties": {
    "@timestamp": {
      "type": "date"
    },
    "balance": {
      "type": "float"
    }
  }
  }
}
POST discuss-test/_doc
{
 "@timestamp" : "2022-12-22T17:44:11.891Z",
 "balance" : 11555.7125 
}

POST discuss-test/_doc
{
 "@timestamp" : "2022-12-22T17:45:11.891Z",
 "balance" : 11666.7725 
}

GET discuss-test/_search
{
  "fields": [
    "*"
  ]
}

#Results Notice the difference between the `_source` and the `fields`

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "discuss-test",
        "_id": "xkOxPIUBrWRX1Zc6vqbo",
        "_score": 1,
        "_source": {
          "@timestamp": "2022-12-22T17:44:11.891Z",
          "balance": 11555.7125 <!------ _source what you sent
        },
        "fields": {
          "@timestamp": [
            "2022-12-22T17:44:11.891Z"
          ],
          "balance": [
            11555.713 <!- Single Precision Float :( what was stored and used
          ]
        }
      },
      {
        "_index": "discuss-test",
        "_id": "x0OxPIUBrWRX1Zc6vqb5",
        "_score": 1,
        "_source": {
          "@timestamp": "2022-12-22T17:45:11.891Z",
          "balance": 11666.7725
        },
        "fields": {
          "@timestamp": [
            "2022-12-22T17:45:11.891Z"
          ],
          "balance": [
            11666.772
          ]
        }
      }
    ]
  }
}

```

Now lets do it with a `double`

```auto
DELETE discuss-test

PUT discuss-test/
{
  "mappings" : {
  "properties": {
    "@timestamp": {
      "type": "date"
    },
    "balance": {
      "type": "double"
    }
  }
  }
}

POST discuss-test/_doc
{
 "@timestamp" : "2022-12-22T17:44:11.891Z",
 "balance" : 11555.7125 
}

POST discuss-test/_doc
{
 "@timestamp" : "2022-12-22T17:45:11.891Z",
 "balance" : 11666.7725 
}

GET discuss-test/_search
{
  "fields": [
    "*"
  ]
}

# Results Happy Days!

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "discuss-test",
        "_id": "ykOzPIUBrWRX1Zc6kaYi",
        "_score": 1,
        "_source": {
          "@timestamp": "2022-12-22T17:44:11.891Z",
          "balance": 11555.7125 <!--- Source
        },
        "fields": {
          "@timestamp": [
            "2022-12-22T17:44:11.891Z"
          ],
          "balance": [
            11555.7125 <!--- Stored Field 
          ]
        }
      },
      {
        "_index": "discuss-test",
        "_id": "y0OzPIUBrWRX1Zc6kaYu",
        "_score": 1,
        "_source": {
          "@timestamp": "2022-12-22T17:45:11.891Z",
          "balance": 11666.7725 
        },
        "fields": {
          "@timestamp": [
            "2022-12-22T17:45:11.891Z"
          ],
          "balance": [
            11666.7725
          ]
        }
      }
    ]
  }
}

```

And Discover

 ![Screen Shot 2022-12-22 at 5.59.39 PM](https://us1.discourse-cdn.com/elastic/original/3X/3/d/3db4188987ec9f9c092a3bcbaf7814083744d457.png)

---

_[View the full topic](https://discuss.elastic.co/t/float-type-rounding-issues/321859)._
