Function MAXINT()

Hello dear TULIPians,

I try to create to do the following calculation:

@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:

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

It makes the expression illegible :disappointed_relieved:.

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

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?

Hi Remi!

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

  • Olga

Hello Thorsten,

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

1 Like

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, TULIP calculate 0.5202999999999989 :disappointed_relieved:.

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.

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

1 Like

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

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

1 Like