# Writedlm gives wrong output

**URL:** <https://discourse.julialang.org/t/writedlm-gives-wrong-output/23528>\
**Category:** General Usage\
**Created:** [April 25, 2019, 7:25pm UTC](https://discourse.julialang.org/t/writedlm-gives-wrong-output/23528 "2019-04-25T19:25:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JianghuiDu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jianghuidu/32/8028_2.png) [@JianghuiDu](https://discourse.julialang.org/u/JianghuiDu)\
**Post date:** [April 25, 2019, 7:25pm UTC](https://discourse.julialang.org/t/writedlm-gives-wrong-output/23528/1 "2019-04-25T19:25:57Z")

</div>

I use `writedlm` to save my matrices in `.txt` files and I found that occasionally the outputs are wrong, specifically the place of the decimal points. It happens for example `0.04` is saved as `0.4`. It only happens the first time I save the data, if I `writedlm` the same matrix again then the results are correct. I wonder if anybody have seen this problem. It is not reproducible but happens quite often. I have Windows 10 and Julia 1.1.0.

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [April 25, 2019, 7:54pm UTC](https://discourse.julialang.org/t/writedlm-gives-wrong-output/23528/2 "2019-04-25T19:54:58Z")

</div>

Are you sure it is not writing `0.4e-1` to the file?

---

<div class="post-metadata">

**Author:** ![JianghuiDu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jianghuidu/32/8028_2.png) [@JianghuiDu](https://discourse.julialang.org/u/JianghuiDu)\
**Post date:** [April 25, 2019, 8:13pm UTC](https://discourse.julialang.org/t/writedlm-gives-wrong-output/23528/3 "2019-04-25T20:13:40Z")

</div>

Also I’ve since been using `CSV.write` and never had a problem. But `writedlm` is so much faster and I’d prefer to use it.

---

<div class="post-metadata">

**Author:** ![JianghuiDu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jianghuidu/32/8028_2.png) [@JianghuiDu](https://discourse.julialang.org/u/JianghuiDu)\
**Post date:** [April 25, 2019, 8:13pm UTC](https://discourse.julialang.org/t/writedlm-gives-wrong-output/23528/4 "2019-04-25T20:13:42Z")

</div>

I’m positive. The first time I spotted this was because I copyed and pasted the `.txt` data into excel and I was comparing the two ODE results with slightly different parameters. I knew that the results should be different but not THAT different. Initially I thought there was something wrong with my code or maybe the result was really sensitive to the the parameter. But when I reran the code again, including `writedlm` the difference became much smaller and within the range that I excepted. Then I noticed that if I start julia again and run the code with the same parameters the huge difference appeared again, then I knew it’s not a problem of my code but `writedlm` . I then spotted that the decimal place in the first `.txt` was wrong. Like I said that if I call `writedlm` multiple times the 2nd, 3rd etc. `.txt` are all correct. It only happens when I first call `writedlm` in a new julia session.

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [April 25, 2019, 8:29pm UTC](https://discourse.julialang.org/t/writedlm-gives-wrong-output/23528/5 "2019-04-25T20:29:17Z")

</div>

I guess we need an example of how this happens (to reproduce it). It should be just a few lines of code.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 26, 2019, 6:11am UTC](https://discourse.julialang.org/t/writedlm-gives-wrong-output/23528/6 "2019-04-26T06:11:54Z")

</div>

Please make an MWE, and include `versioninfo()`.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [April 26, 2019, 1:33pm UTC](https://discourse.julialang.org/t/writedlm-gives-wrong-output/23528/7 "2019-04-26T13:33:32Z")

</div>

Even if it’s not minimal or 100% repeatable, please do post something that sometimes reproduces it. This would be a very serious bug.
