# Accuracy of floats saved with writedlm

**URL:** <https://discourse.julialang.org/t/accuracy-of-floats-saved-with-writedlm/17026>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 31, 2018, 8:14pm UTC](https://discourse.julialang.org/t/accuracy-of-floats-saved-with-writedlm/17026 "2018-10-31T20:14:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 31, 2018, 8:14pm UTC](https://discourse.julialang.org/t/accuracy-of-floats-saved-with-writedlm/17026/1 "2018-10-31T20:14:35Z")

</div>

Following the discussion on [More control over writedlm formatting](https://discourse.julialang.org/t/more-control-over-writedlm-formatting/2840) I understood that _the_ tool to save numeric matrices was `wrtiedlm`. I have a bunch of small `Matrix{Float64}`s (some times just `1x2`, sometimes `~500x3`, never more) that I need to save.  
In [DelimitedFiles’s documentation](https://docs.julialang.org/en/v1/stdlib/DelimitedFiles/#DelimitedFiles.readdlm-Tuple%7BAny,AbstractChar,Type,AbstractChar%7D) it’s mentioned that “the source can be a text file, stream or byte array”.  
My question is: since I’m saving floats (and not integers), in order to increase accuracy or decrease format-dependent rounding, should I be saving my matrices as a “byte array” instead of a “text file”? And if so, how exactly? All I know of is:

```julia
writedlm("tmp.csv", rand(3))

```

I’ll just close with that after some experimentation, the numbers saved had a whopping 18 digits to them, so I think I’m good…

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 31, 2018, 8:20pm UTC](https://discourse.julialang.org/t/accuracy-of-floats-saved-with-writedlm/17026/2 "2018-10-31T20:20:41Z")

</div>

If you are saving them for later use in Julia, consider using JLD2.jl

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 31, 2018, 8:21pm UTC](https://discourse.julialang.org/t/accuracy-of-floats-saved-with-writedlm/17026/3 "2018-10-31T20:21:07Z")

</div>

> [@dpsanders](#):
>
> later use in Julia

No, it needs to be universal forever.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 31, 2018, 8:21pm UTC](https://discourse.julialang.org/t/accuracy-of-floats-saved-with-writedlm/17026/4 "2018-10-31T20:21:40Z")

</div>

When writing a `.csv` file with `writedlm`, a string representation of whatever you’re writing is saved instead of the binary representation. If the files are not meant to be read by humans, consider using a package with saving binary representation instead.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 31, 2018, 8:22pm UTC](https://discourse.julialang.org/t/accuracy-of-floats-saved-with-writedlm/17026/5 "2018-10-31T20:22:31Z")

</div>

You would not gain any accuracy. There shouldn’t be any rounding.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [October 31, 2018, 8:25pm UTC](https://discourse.julialang.org/t/accuracy-of-floats-saved-with-writedlm/17026/6 "2018-10-31T20:25:23Z")

</div>

> [@kristoffer.carlsson](#):
>
> You would not gain any accuracy. There shouldn’t be any rounding.

This is very comforting, thank you. While

> [@Sukera](#):
>
> the files are not meant to be read by humans

I feel `writedlm` is straightforward and fast. Seems like it’ll do the trick.
