# Logstash converting empty string into 0.0

**URL:** https://discuss.elastic.co/t/logstash-converting-empty-string-into-0-0/188797
**Category:** Logstash
**Created:** [July 3, 2019, 7:08pm UTC](https://discuss.elastic.co/t/logstash-converting-empty-string-into-0-0/188797 "2019-07-03T19:08:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![rahulkothanath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahulkothanath/32/99122_2.png) [@rahulkothanath](https://discuss.elastic.co/u/rahulkothanath)
#### Post date: [July 3, 2019, 7:08pm UTC](https://discuss.elastic.co/t/logstash-converting-empty-string-into-0-0/188797/1 "2019-07-03T19:08:49Z")

</div>

Hi,  
I am converting an amount value into float as follows.

```
mutate{
convert => {
 "AMT" => "float"

 }

```

if "AMT"="" empty spcae ,it give 0.0 as the conversion output. this may mislead people since it is an amount field.

is there a way to avoid this problem..?

thanks for reading and helping.

---

<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: [July 3, 2019, 7:27pm UTC](https://discuss.elastic.co/t/logstash-converting-empty-string-into-0-0/188797/2 "2019-07-03T19:27:35Z")

</div>

Yes, a mutate will do that. You could make the mutate conditional upon AMT not being blank.

```
if [AMT] != "" {
    [...]
```

---

<div class="post-metadata">

### Author: ![rahulkothanath](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahulkothanath/32/99122_2.png) [@rahulkothanath](https://discuss.elastic.co/u/rahulkothanath)
#### Post date: [July 3, 2019, 8:05pm UTC](https://discuss.elastic.co/t/logstash-converting-empty-string-into-0-0/188797/3 "2019-07-03T20:05:05Z")

</div>

that works. Actually I have to convert more than 10 fields like this and checking each one of this doesnt look good to me. is there a way to do this using ruby filter with for loop on a list of fields to convert?

thanks for reading and helping.

---

<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: [July 3, 2019, 9:15pm UTC](https://discuss.elastic.co/t/logstash-converting-empty-string-into-0-0/188797/4 "2019-07-03T21:15:54Z")

</div>

Yes, you could do something like this:

```
    ruby {
        code => '
            ["amount", "foo", "bar", "baz"].each { |x|
                s = event.get(x)
                if s and (s.to_f.to_s == s) then
                    event.set(x, s.to_f)
                end
            }
        '
    }
```

---

<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: [July 31, 2019, 9:17pm UTC](https://discuss.elastic.co/t/logstash-converting-empty-string-into-0-0/188797/5 "2019-07-31T21:17:58Z")

</div>

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