# Float 1.0 does not get converted to boolean true

**URL:** https://discuss.elastic.co/t/float-1-0-does-not-get-converted-to-boolean-true/230231
**Category:** Logstash
**Created:** [April 28, 2020, 6:04pm UTC](https://discuss.elastic.co/t/float-1-0-does-not-get-converted-to-boolean-true/230231 "2020-04-28T18:04:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![sc5283](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@sc5283](https://discuss.elastic.co/u/sc5283)
#### Post date: [April 28, 2020, 6:04pm UTC](https://discuss.elastic.co/t/float-1-0-does-not-get-converted-to-boolean-true/230231/1 "2020-04-28T18:04:40Z")

</div>

logstash 7.6.2

From [mutate filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html)  
specifies float 1.0 is converted to boolean true  
but this is not the case, all others work (0, 0.0, "0", etc).

I have tried also the translate filter with no success  
input : ---\> {"isBool":1.0}

```auto
     input { stdin { } }
     filter {
     
     	translate {
     		field => "[isBool]"
     		dictionary => [
     			"0.0", false,
     			0, false,
     			"1.0", true,
     			1, true,
     			1.0, true,
     			"1", true
     		]
     	}
       ## or only the mutate/convert
        mutate { convert => { "isBool" => "boolean" } }
     }
     
     output { stdout { codec => rubydebug } }

```

--debug provides the following:  
[WARN] .... [[main]\>worker10] mutate - Failed to convert 0.1e1 into boolean.

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [April 28, 2020, 6:16pm UTC](https://discuss.elastic.co/t/float-1-0-does-not-get-converted-to-boolean-true/230231/2 "2020-04-28T18:16:00Z")

</div>

> [@sc5283](#):
>
> Failed to convert 0.1e1 into boolean.

Interesting. The [code](https://github.com/logstash-plugins/logstash-filter-mutate/blob/250d7f68c389e34965e3139005115a9655ff5129/lib/logstash/filters/mutate.rb#L213) tries to match the value against the regexp /^(true|t|yes|y|1|1.0)$/i and 0.1e1 would indeed not match that.

---

<div class="post-metadata">

### Author: ![sc5283](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@sc5283](https://discuss.elastic.co/u/sc5283)
#### Post date: [April 28, 2020, 6:40pm UTC](https://discuss.elastic.co/t/float-1-0-does-not-get-converted-to-boolean-true/230231/3 "2020-04-28T18:40:56Z")

</div>

Any suggestions to workaround the issue? How do I compare the float/scientific notation value?

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [April 28, 2020, 7:15pm UTC](https://discuss.elastic.co/t/float-1-0-does-not-get-converted-to-boolean-true/230231/4 "2020-04-28T19:15:14Z")

</div>

You might be able to write a ruby filter that compares your field to 1 and makes it an integer if it is equal to one, or maybe even

```
k = "someField"
v = event.get(k)
if v.to_i.to_f == v
     v = v.to_i
     event.set(k, v)
end
```

---

<div class="post-metadata">

### Author: ![sc5283](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@sc5283](https://discuss.elastic.co/u/sc5283)
#### Post date: [April 28, 2020, 7:32pm UTC](https://discuss.elastic.co/t/float-1-0-does-not-get-converted-to-boolean-true/230231/5 "2020-04-28T19:32:56Z")

</div>

Thank you  
I found this easier :

```auto
    	mutate { convert => { "isBool" => "integer" }	}
    	mutate { convert => { "isBool" => "boolean" } }

```

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [April 28, 2020, 10:19pm UTC](https://discuss.elastic.co/t/float-1-0-does-not-get-converted-to-boolean-true/230231/6 "2020-04-28T22:19:24Z")

</div>

Yes, that would work if it is always 1.0, my code handles 1.1 as well (by not changing it). If you do not need that then your code is simpler, which generally means better.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 26, 2020, 10:19pm UTC](https://discuss.elastic.co/t/float-1-0-does-not-get-converted-to-boolean-true/230231/7 "2020-05-26T22:19:25Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
