# .Q.f output unexpected value in kdb4.0

**URL:** <https://forum.kx.com/t/q-f-output-unexpected-value-in-kdb4-0/13348>\
**Category:** Community Support\
**Tags:** imported, kdb-and-q\
**Created:** [September 20, 2023, 12:00am UTC](https://forum.kx.com/t/q-f-output-unexpected-value-in-kdb4-0/13348 "2023-09-20T00:00:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![baichen](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@baichen](https://forum.kx.com/u/baichen)\
**Post date:** [September 20, 2023, 12:00am UTC](https://forum.kx.com/t/q-f-output-unexpected-value-in-kdb4-0/13348/1 "2023-09-20T00:00:00Z")

</div>

[https://learninghub.kx.com/forums/topic/q-f-output-unexpected-value-in-kdb4-0](https://learninghub.kx.com/forums/topic/q-f-output-unexpected-value-in-kdb4-0)

&nbsp;

&nbsp;

Hello all,

Came across a problem with .Q.f .

We expected the first output to be 4194304.98 .

I saw this issue only in kdb4.0.

Output in kdb3.5 is expected.

Any advice is appreciated.

---

<div class="post-metadata">

**Author:** ![rocuinneagain](https://sea2.discourse-cdn.com/flex002/user_avatar/forum.kx.com/rocuinneagain/32/287_2.png) [@rocuinneagain](https://forum.kx.com/u/rocuinneagain)\
**Post date:** [September 20, 2023, 12:00am UTC](https://forum.kx.com/t/q-f-output-unexpected-value-in-kdb4-0/13348/2 "2023-09-20T00:00:00Z")

</div>

From 3.6 Readme

```
2018.09.26 NEW added -27! as a more precise, builtin version of .Q.f. n.b. It is atomic and doesn't take P into account. e.g. q)("123456789.457";"123456790.457")~-27!(3i;0 1+2#123456789.4567)
```

The definition of `.Q.f` changed at this time also - when comparing `q.k` file definitions:

`3.6.0 2018.09.10`

```
f:{$[^y;"";y<0;"-",f[x;-y];y<1;1_f[x;10+y];9e15>j:"j"$y*/x#10;(x_j),".",(x:-x)#j:$j;$y]}
```

`3.6.0 2018.10.03`

```
f:{$[^y;"";y<0;"-",f[x;-y];y<1;1_f[x;10+y];9e15>j:"j"$y*prd x#10f;(x_j),".",(x:-x)#j:$j;$y]}
```
&nbsp;

Floating point numbers are not exact and such behaviours should be expected in certain cases:

[https://code.kx.com/q/basics/precision/](https://code.kx.com/q/basics/precision/")

&nbsp;

They are approximations:

```
q)P 
0 
q)4194303.975 
4194303.9750000001 
q)4194304.975 
4194304.9749999996
```
&nbsp;
The same in C:

```
int main() { double x = 4194303.975; printf("%10.10fn",x); }
```

Result:

```
4194303.9750000001
```
&nbsp;

If you find that you need exact decimal rounding, consider whether you actually need to operate in fixed-point, rather than floating-point.  
e.g. keep monetary values in integral millicents etc.

&nbsp;

&nbsp;

&nbsp;
