# Function MAXINT()

**URL:** <https://community.tulip.co/t/function-maxint/13029>\
**Category:** Product Suggestions\
**Created:** [November 5, 2024, 4:29pm UTC](https://community.tulip.co/t/function-maxint/13029 "2024-11-05T16:29:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![remi.bayon](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/remi.bayon/32/8092_2.png) [@remi.bayon](https://community.tulip.co/u/remi.bayon)\
**Post date:** [November 5, 2024, 4:29pm UTC](https://community.tulip.co/t/function-maxint/13029/1 "2024-11-05T16:29:20Z")

</div>

Hello dear TULIPians,

I try to create to do the following calculation:

```auto
@var_a = ROUND(@var_b, MAX(@var_c, 3))

```

But unfortunately, in the expression editor, the function MAX() return a number and the 2nd argument of ROUND() must be an integer…

The only two solutions I have until now is to do:

```auto
@var_a = ROUND(@var_b, TEXTTOINTEGER(TOTEXT(MAX(@var_c, 3))))

```

```auto
@var_a = ROUND(@var_b, ROUND(MAX(@var_c, 3)))

```

It makes the expression illegible 😥.

Is there another way to do this calculation?  
Or maybe, a new product suggestion could be to add the function MAXINT() which return an integer.  
In the same spirit, a function NUMBERTOINTEGER() could be nice.

Best regards,  
Rémi Bayon

---

<div class="post-metadata">

**Author:** ![thorsten.langner](https://avatars.discourse-cdn.com/v4/letter/t/4bbf92/32.png) [@thorsten.langner](https://community.tulip.co/u/thorsten.langner)\
**Post date:** [November 5, 2024, 4:36pm UTC](https://community.tulip.co/t/function-maxint/13029/2 "2024-11-05T16:36:06Z")

</div>

For a `NUMBERTOINTEGER()`you need to define the direction (up or down or round)  
`FLOOR()` and `CEIL()` and `ROUND()` are exactly `NUMBERTOINTEGER()`with this information.

What do you expect NUMBERTOINTEGER() to do?

---

<div class="post-metadata">

**Author:** ![OlgaStroilova](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/olgastroilova/32/7199_2.png) [@OlgaStroilova](https://community.tulip.co/u/OlgaStroilova)\
**Post date:** [November 5, 2024, 9:54pm UTC](https://community.tulip.co/t/function-maxint/13029/3 "2024-11-05T21:54:06Z")

</div>

Hi Remi!

I’m also interested in your use case- what is the calculation you’re hoping to do here?

- Olga

---

<div class="post-metadata">

**Author:** ![remi.bayon](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/remi.bayon/32/8092_2.png) [@remi.bayon](https://community.tulip.co/u/remi.bayon)\
**Post date:** [November 6, 2024, 9:31am UTC](https://community.tulip.co/t/function-maxint/13029/4 "2024-11-06T09:31:22Z")

</div>

Hello Thorsten,

Yes, you are right, `NUMBERTOINTEGER()` already exist via `FLOOR()`, `CEIL()` and `ROUND()`.  
Sorry for it, forget this part of my message.

---

<div class="post-metadata">

**Author:** ![remi.bayon](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/remi.bayon/32/8092_2.png) [@remi.bayon](https://community.tulip.co/u/remi.bayon)\
**Post date:** [November 6, 2024, 9:49am UTC](https://community.tulip.co/t/function-maxint/13029/5 "2024-11-06T09:49:13Z")

</div>

Hello Olga,

Thanks a lot for your question because I asked for a solution without explained the root-cause of my problem.

I have 2 **inputs** :

- The value of a sensor: e.g. 21.3253.
- A target: e.g. 20.805.

The **output** I am looking for is the gap.  
So, with my example 21.3253-20.805=0.5203.

But unfortunately, due to the famous [round-off error](https://en.wikipedia.org/wiki/Round-off_error), TULIP calculate 0.5202999999999989 😥.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/a/ac928d12c8e4e0da8f7627c8c814c128190ebfa9.png)

Most of the time, this kind of errors don’t matter. But here, I send this value to our ERP SAP, and SAP re-uses the value. So, it must be exact.

> **Finally, what is the calculation you’re hoping to do here?**

The precision of my sensor is variable and I know it. My target always have 3 digits max after the comma.  
So, doing ` @var_gap = ROUND(@var_gap, ROUND(MAX(@var_precisionSensor, 3)))` kills the round-off error.

---

<div class="post-metadata">

**Author:** ![thorsten.langner](https://avatars.discourse-cdn.com/v4/letter/t/4bbf92/32.png) [@thorsten.langner](https://community.tulip.co/u/thorsten.langner)\
**Post date:** [November 6, 2024, 11:47am UTC](https://community.tulip.co/t/function-maxint/13029/6 "2024-11-06T11:47:49Z")

</div>

Okay I see…

I find your approach good.  
For more readability you could decide to calculate the precision in a previous step:  
`Data Manipulation`\>`Store`\>`Expression` `ROUND(MAX(@var_precisionSensor, 3))`\> `Variable` \> `Precision`

`Data Manipulation`\>`Store`\>`Expression` `ROUND(@var_gap,@Variable.Precision)`\> `Variable` \> `var_gap`

But there are also other approaches as:

`(1000000 * @variable.value_sensor - 1000000 * @variable.target)/1000000`

---

<div class="post-metadata">

**Author:** ![OlgaStroilova](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/olgastroilova/32/7199_2.png) [@OlgaStroilova](https://community.tulip.co/u/OlgaStroilova)\
**Post date:** [November 6, 2024, 9:45pm UTC](https://community.tulip.co/t/function-maxint/13029/8 "2024-11-06T21:45:06Z")

</div>

Thanks Remi,

The use case is detailed and makes sense. Understand the legibility issues with both ROUND and NUMBERTOINTEGER here.

I’ll connect with the team on what’s the most elegant solution, and also reach out if I have followups.

It sounds like you have a workaround for now, but that workaround is difficult to read … how often do you have to use expressions like this?

- Olga

---

<div class="post-metadata">

**Author:** ![remi.bayon](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/remi.bayon/32/8092_2.png) [@remi.bayon](https://community.tulip.co/u/remi.bayon)\
**Post date:** [November 8, 2024, 8:56am UTC](https://community.tulip.co/t/function-maxint/13029/9 "2024-11-08T08:56:14Z")

</div>

Hello both,

Thanks for your answers.  
It was a product suggestion if there is an opportunity for it.

For now, I can continue with `@var_a = ROUND(@var_b, ROUND(MAX(@var_c, 3)))`.

Best regards,  
Rémi Bayon
