Announcement

REXYGEN forum has been moved. This one is closed.
Head over to the new REXYGEN Community Forum at https://forum.rexygen.com.

Looking forward to meeting you there!
 

#1 2017-11-29 22:51:33

mikeyh
Member
From: New Zealand
Registered: 2016-04-28
Posts: 44

Rounding decimals

Hi All,

I've had a good search of the function block manual. I can't seem to find a block that will round a number up to a desired amount of decimal places.

I'm willing to make one up or something that works but I'd prefer to use a standard block if one exists.

Cheers

Mike

Offline

#2 2017-12-01 15:21:45

tomáš čechura
Administrator
Registered: 2016-02-22
Posts: 371

Re: Rounding decimals

Hi Mike,

thank you for this interesting question. I must say that there is no specific function block which does the thing. However, it is definitely possible to achieve such behaviour.

One option is to convert the Real number to String and then back to Real - function blocks RTOS and STOR. Be sure to setup RTOS parameters according to desired amount of decimals and to select mode "2:normal".

Other option is to multiply the real number by (desiredAmountOfDecimals)x10, then round by means of RTOI function block and finally divide by (desiredAmountOfDecimals)x10. Function block sequence is therefore MUL, RTOI and DIV.

Hope it is useful for you.

Cheers, Tomas

Offline

#3 2017-12-03 20:05:04

mikeyh
Member
From: New Zealand
Registered: 2016-04-28
Posts: 44

Re: Rounding decimals

Hey Tomas,

Thank you for your help as always. I have used both methods (just to be different!) and created subsystems for future use.

Thanks again.

Mike

Offline

Board footer

Powered by FluxBB