# Divising a DateTime by 1 or 10 yields different floating point precision

**URL:** <https://discourse.julialang.org/t/divising-a-datetime-by-1-or-10-yields-different-floating-point-precision/117347>\
**Category:** New to Julia\
**Created:** [July 22, 2024, 2:33pm UTC](https://discourse.julialang.org/t/divising-a-datetime-by-1-or-10-yields-different-floating-point-precision/117347 "2024-07-22T14:33:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)\
**Post date:** [July 22, 2024, 2:33pm UTC](https://discourse.julialang.org/t/divising-a-datetime-by-1-or-10-yields-different-floating-point-precision/117347/1 "2024-07-22T14:33:31Z")

</div>

I have come to an inexplicable (at least for me at the moment) behavior in Julia

```julia
julia> using Dates
julia> Dates.value(Minute(60)) / 1 * 38.849
2330.9399999999996
julia> Dates.value(Dates.value(Minute(60)) * 38.849
2330.9399999999996
julia> Dates.value(Minute(60)) / 10 * 38.849
233.094
julia> Dates.value(Minute(60)) * 3.8849
233.094

```

Can you explain why the first two don’t yield the same precision as the two latest?

---

<div class="post-metadata">

**Author:** ![screw\_dog](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/screw_dog/32/48119_2.png) [@screw\_dog](https://discourse.julialang.org/u/screw_dog)\
**Post date:** [July 22, 2024, 2:39pm UTC](https://discourse.julialang.org/t/divising-a-datetime-by-1-or-10-yields-different-floating-point-precision/117347/2 "2024-07-22T14:39:37Z")

</div>

This isn’t about `Dates`, but rather that floating point arithmetic doesn’t work quite how one may expect. See:

```julia
3.8849 == 38.849/10 # false

```

This isn’t even about Julia, since Julia implements the industry standard IEEE 754 that most languages do.

Essentially, if you’re using floats you can’t usually use `==` as the order of operations can matter and slight differences can occur.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 22, 2024, 2:42pm UTC](https://discourse.julialang.org/t/divising-a-datetime-by-1-or-10-yields-different-floating-point-precision/117347/3 "2024-07-22T14:42:00Z")

</div>

That question is common enough that there’s a PSA:

> [@PSA: floating-point arithmetic](https://discourse.julialang.org/t/psa-floating-point-arithmetic/8678):
>
> Sometimes people are surprised by the results of floating-point calculations such as julia\> 5/6 0.8333333333333334 # shouldn't the last digit be 3? julia\> 2.6 - 0.7 - 1.9 2.220446049250313e-16 # shouldn't the answer be 0? These are not bugs in Julia. They’re consequences of the IEEE-standard 64-bit binary representation of floating-point numbers that is burned into computer hardware, which Julia and many other languages use by default. Brief explanation You can t…

---

<div class="post-metadata">

**Author:** ![K5Julien](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/k5julien/32/210626_2.png) [@K5Julien](https://discourse.julialang.org/u/K5Julien)\
**Post date:** [July 22, 2024, 2:59pm UTC](https://discourse.julialang.org/t/divising-a-datetime-by-1-or-10-yields-different-floating-point-precision/117347/4 "2024-07-22T14:59:19Z")

</div>

Thanks for your replies 🙂  
Just in case for future readers, what I actually wanted to ask has it [answers here](https://discourse.julialang.org/t/operations-with-time-duration/64983) 😃
