# JSONata bug? how come 0.1 \> 0.1 returns true?

**URL:** <https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252>\
**Category:** General\
**Created:** [30 May 2022 12:30 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252 "2022-05-30T12:30:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![bogorad](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bogorad/32/18900_2.png) [@bogorad](https://discourse.nodered.org/u/bogorad)\
**Post date:** [30 May 2022 12:30 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/1 "2022-05-30T12:30:28Z")

</div>

Am I missing something? This is from [try.jsonata.org](http://try.jsonata.org) but it certainly is the same in Node-red. This should be 'false', right?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e12d56c65edccf78c140139e009b5c92c987001.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [30 May 2022 12:42 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/2 "2022-05-30T12:42:35Z")

</div>

You can see the same thing in JavaScript:

```auto
$ node
Welcome to Node.js v16.13.1.
Type ".help" for more information.
> 1.1-1>0.1
true

```

When you evaluate `1.1-1` you can see what is happening:

```auto
> 1.1-1
0.10000000000000009

```

Welcome to the way JavaScript represents floating point numbers.

---

<div class="post-metadata">

**Author:** ![bogorad](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bogorad/32/18900_2.png) [@bogorad](https://discourse.nodered.org/u/bogorad)\
**Post date:** [30 May 2022 12:53 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/3 "2022-05-30T12:53:33Z")

</div>

Thank you! I thought I was going crazy 🙂

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [30 May 2022 13:27 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/4 "2022-05-30T13:27:05Z")

</div>

Not javascript alone...

```auto
pi@nrpi:~ $ python3
Python 3.6.3 (default, Apr 26 2019, 12:57:09)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1.1-1
0.10000000000000009
>>>

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [30 May 2022 21:03 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/5 "2022-05-30T21:03:26Z")

</div>

Interesting. PowerShell gets it right.

```auto
> 1.1-1
0.1

```

And then screws it up!

```auto
> 1.1-1 -gt 0.1
True
> 1.1 -gt 1.1
False

```

R also messes up. As does Lua and PHP. Got bored after that!

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [30 May 2022 21:39 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/6 "2022-05-30T21:39:59Z")

</div>

> [@TotallyInformation](#):
>
> R also messes up. As does Lua and PHP. Got bored after that!

haha yeah, its an float thing. Unfortunately you have to know this to um, know this 🤷‍♂️

So where it "looks" like powershell gets it right, whats likely happening is it rounds (for display) after x amount of decimal places (e.g. 0.10000000000000009 is rounded to 0.10000000 which is then shown as 0.1) but the actual number is still 0.10000000000000009 therefore `1.1 - 1 == 0.10000000000000009` and then `0.10000000000000009 -gt 0.1 == true`. I'd rather be told `1.1 - 1 == 0.10000000000000009` then at least i can understand why `1.1-1 -gt 0.1 == true`

---

<div class="post-metadata">

**Author:** ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)\
**Post date:** [31 May 2022 07:33 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/7 "2022-05-31T07:33:43Z")

</div>

It's still wonky 1.1-1 = 0.1, where does that 9 come from lol

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [31 May 2022 07:35 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/8 "2022-05-31T07:35:58Z")

</div>

> [@9toejack](#):
>
> where does that 9 come from lol

maybe from your user name @9toejack 😃

---

<div class="post-metadata">

**Author:** ![9toejack](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/9toejack/32/56868_2.png) [@9toejack](https://discourse.nodered.org/u/9toejack)\
**Post date:** [31 May 2022 07:37 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/9 "2022-05-31T07:37:44Z")

</div>

walked into that one! maybe i should change my profile pic to my foot!

---

<div class="post-metadata">

**Author:** ![mrdvt92](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrdvt92/32/33122_2.png) [@mrdvt92](https://discourse.nodered.org/u/mrdvt92)\
**Post date:** [7 June 2022 17:00 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/10 "2022-06-07T17:00:54Z")

</div>

It is just how floating point math works. I'm sure all of these programs are using the same C compiler.

> $ perl -e 'printf "%0.30f\n", $\_ for 1.1-1.0, 0.1, 13.1-13'  
> 0.100000000000000088817841970013  
> 0.100000000000000005551115123126  
> 0.099999999999999644728632119950

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [7 June 2022 17:04 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/11 "2022-06-07T17:04:16Z")

</div>

> [@mrdvt92](#):
>
> I'm sure all of these programs are using the same C compiler

Its not a compiler issue, it is an IEEE 754 design issue. You only have 64 bits to fit an almost infinite amount of numbers into. It simply has limitations.

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f91a4cb6632354331748232e39dc1b36f726127e.jpeg "Why 0.1 + 0.2 === 0.30000000000000004: Implementing IEEE 754 in JS") ](https://www.youtube.com/watch?v=wPBjd-vb9eI)

---

<div class="post-metadata">

**Author:** ![bogorad](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bogorad/32/18900_2.png) [@bogorad](https://discourse.nodered.org/u/bogorad)\
**Post date:** [7 June 2022 17:17 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/12 "2022-06-07T17:17:58Z")

</div>

It's a design issue. There's BCD and there's fixed-point arithmetic. But for some reason, they chose to go with floating-point.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 August 2022 17:18 UTC](https://discourse.nodered.org/t/jsonata-bug-how-come-0-1-0-1-returns-true/63252/13 "2022-08-06T17:18:23Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
