# Why do Rationals promote to Floats

**URL:** <https://discourse.julialang.org/t/why-do-rationals-promote-to-floats/28526>\
**Category:** New to Julia\
**Created:** [September 8, 2019, 2:31am UTC](https://discourse.julialang.org/t/why-do-rationals-promote-to-floats/28526 "2019-09-08T02:31:07Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [September 8, 2019, 6:26am UTC](https://discourse.julialang.org/t/why-do-rationals-promote-to-floats/28526/2 "2019-09-08T06:26:37Z")

</div>

> [@thelonious](#):
>
> I’m wondering, is there an explanation or discussion about this that I can read? If I wanted to reverse this behavior (convert the Float to a Rational in this case), is that something I can override?

I think the reason is that

1. calculations with eg `Rational{Int64}` would quickly overflow for the denominator,

2. the results of transcendental functions (`exp`) cannot be a rational number in general.

So it is safest to promote to `Float64`. Of course, the trade-off is floating point inaccuracy.

Generally, I would just _not_ promote but leave it to the operation. For a more specific workaround, please provide more context.

> [@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 …

---

_[View the full topic](https://discourse.julialang.org/t/why-do-rationals-promote-to-floats/28526)._
