# My decimal is too small

**URL:** https://discourse.processing.org/t/my-decimal-is-too-small/19041
**Category:** Beginners
**Created:** [March 26, 2020, 3:20pm UTC](https://discourse.processing.org/t/my-decimal-is-too-small/19041 "2020-03-26T15:20:49Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Cybernet](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@Cybernet](https://discourse.processing.org/u/Cybernet)
#### Post date: [March 26, 2020, 3:20pm UTC](https://discourse.processing.org/t/my-decimal-is-too-small/19041/1 "2020-03-26T15:20:49Z")

</div>

Here is my example of my code:

```auto

value = -1 / (value1 - value2);
println(xdirection);

```

It is very simple. I am trying to take the negative reciprocal of a value. But the number is too small, and when I try to print the vale, it shows up as `0.0`. I tried to use `double`, but even with `double`, the value is still `0.0`. Is there a way where I can calculate small numbers?

Even if I do this:

```auto
println(-1/100);

```

The value still shows up as zero. How can I fix this? Thank you

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [March 26, 2020, 3:25pm UTC](https://discourse.processing.org/t/my-decimal-is-too-small/19041/2 "2020-03-26T15:25:05Z")

</div>

> [@Cybernet](#):
>
> println(-1/100);

Try

println(-1.0/100.0f);

---

<div class="post-metadata">

### Author: ![Cybernet](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@Cybernet](https://discourse.processing.org/u/Cybernet)
#### Post date: [March 26, 2020, 4:45pm UTC](https://discourse.processing.org/t/my-decimal-is-too-small/19041/3 "2020-03-26T16:45:50Z")

</div>

what does the f do? Does it stand for float?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [March 26, 2020, 5:08pm UTC](https://discourse.processing.org/t/my-decimal-is-too-small/19041/4 "2020-03-26T17:08:19Z")

</div>

Yes

but .0 alone should be enough

Without the.0: When java assumes there are two ints, it turns the result into int as well

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [March 26, 2020, 5:22pm UTC](https://discourse.processing.org/t/my-decimal-is-too-small/19041/5 "2020-03-26T17:22:19Z")

</div>

@Chrisir === i have got some big problems these days working with this kind of numbers (that i have solved using BigDecimals) and perhaps you can explain what happens: let us take some very simple example:

```auto

void setup(){
  float f = -1.0/100000.0f;
  println(f);
  float fbis = f*10000f;
  println(fbis);
  
}

```

- As you can see at some moment scientific notation is used: when exactly???
- As you can see the 2° returned value is not exact…
- As in my app i work with numbers (lat, long) which are very precise this kind of error is not possible; i have (for experience!) casted the same values to double; result is not the same but it is false…for the first value!

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [March 26, 2020, 5:42pm UTC](https://discourse.processing.org/t/my-decimal-is-too-small/19041/6 "2020-03-26T17:42:18Z")

</div>

I don’t know about these things

Maybe even println does some roundings internally

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [March 26, 2020, 6:16pm UTC](https://discourse.processing.org/t/my-decimal-is-too-small/19041/7 "2020-03-26T18:16:51Z")

</div>

There are an infinite number of floating point numbers and since the computer has finite memory, not _all_ floating point numbers can be stored _ **exactly** _, its _ **impossible** _.

Computers generally use the [IEEE754](https://en.wikipedia.org/wiki/IEEE_754-1985) standard for storing `float` and `double` precision numbers.

In your example code the first line performs the division and stores the result as a float. The actual bit pattern used to store this value is in fact represents the number `-0.00000099999994` which will be displayed as -`1.0E-5` so when multiplied to give `fbis` the results is `-0.099999994`

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [March 26, 2020, 6:19pm UTC](https://discourse.processing.org/t/my-decimal-is-too-small/19041/8 "2020-03-26T18:19:33Z")

</div>

@Chrisir ===  
i dont think that println()is the culprit: in the first case it rounds (nor floor, nor ceil) nothing it returns what is expected… anyway thanks to answer! - As i have told i found the concrete solution using BigDecimals, but i like to understand… And i learn…Knowing that i have simplified (too much?) because you can (that s mys case) get the values as string (in Scientific notation) and have to parse them but how?- Float parseFloat() in this type of case returns weird values, the same for Double.parseDouble()… So what?

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [March 27, 2020, 9:06am UTC](https://discourse.processing.org/t/my-decimal-is-too-small/19041/9 "2020-03-27T09:06:12Z")

</div>

@quark ===  
thanks! - What you say makes sense and so i can see that “full precision” is at max 16 decimals digits.
