# Problems with fractions

**URL:** <https://discourse.processing.org/t/problems-with-fractions/29605>\
**Category:** Beginners\
**Created:** [April 24, 2021, 4:10pm UTC](https://discourse.processing.org/t/problems-with-fractions/29605 "2021-04-24T16:10:00Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [April 24, 2021, 5:06pm UTC](https://discourse.processing.org/t/problems-with-fractions/29605/3 "2021-04-24T17:06:20Z")

</div>

I f you want to do “proper” rational arithmetic, I think ApacheMath supports it for java. Some languages like ruby have support out of the box:-

```ruby
half = Rational(1, 2)
puts half.to_s
calculated = Rational(2 - 1, 2)
puts calculated.to_s
quarter = Rational(1, 4)
puts (quarter + half).to_s

```

Output

```bash
1/2
1/2
3/4

```

The problem with float arithmetic there are always errors, which are worse for small numbers…

In your case you probably want

```java

float x = 1 / 2.0 // that forces float answer from processing (or double answer if using regular java)

```

And accept the errors for now.

---

_[View the full topic](https://discourse.processing.org/t/problems-with-fractions/29605)._
