fround does not appear to work

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
RGV250
Posts: 264
http://meble-kuchenne.info.pl
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

fround does not appear to work

Post by RGV250 »

Hi,
Please move if it is not a bug but I have tried to round some values and it does not appear to work.
This is the output to the web browser, the power values should be rounded to 3 decimal places.
Values not rounded.jpg
Values not rounded.jpg (43.92 KiB) Viewed 1031 times
RPI_EcoEyeMonitor_V1_4A.fcfx
(37.95 KiB) Downloaded 35 times
Bob

RGV250
Posts: 264
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

Re: fround does not appear to work

Post by RGV250 »

Also tried without the space between the "fround" and the bracket, still no good.

medelec35
Matrix Staff
Posts: 1451
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 512 times
Been thanked: 472 times

Re: fround does not appear to work

Post by medelec35 »

Hello.
I have noticed your float calculations don't have a decimal point within them.
What you need to do is force constants to float type by adding .0 at the end.
For example instead of

Code: Select all

Sensor_1_Power = Sensor_1_Current * 240 / 100000
Use

Code: Select all

Sensor_1_Power = Sensor_1_Current * 240.0 / 100000.0
Martin

RGV250
Posts: 264
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

Re: fround does not appear to work

Post by RGV250 »

Hi,
I have tried adding .0 as above but still the same, I then wondered if it was because the current value was not initialised so I added 0.0 to the initial value but still the same.

My only other thought was if it was due to the HexStrToInt macro returning an Int but I cannot figure out how to change the .Return value to a float.

Bob

BenR
Matrix Staff
Posts: 1739
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 440 times
Been thanked: 603 times

Re: fround does not appear to work

Post by BenR »

Hi Bob,

The problem isn't the fround function, you shouldn't need to call this. The problem is the FloatToString$ function defaults to 6 decimal places,

Sensor_1_CurrentWeb = FloatToString$ (Sensor_1_Current)

Change to this instead.

Sensor_1_CurrentWeb = FloatToString$ (Sensor_1_Current, 3)

Or you can bypass the conversion altogether and instead of calling SetOutValue you can call the new SetOutValueFloat macro to pass the floating point value directly.

RGV250
Posts: 264
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

Re: fround does not appear to work

Post by RGV250 »

Hi Ben,
thanks, I forgot you added the SetOutValueFloat for me, it works a treat and does save code.
One question, does this do any rounding or just limit to x dec places. In this instance it is a very tiny value anyway so not worth worrying about but just thought I would ask in case I only go to 1 DP.

Bob

BenR
Matrix Staff
Posts: 1739
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 440 times
Been thanked: 603 times

Re: fround does not appear to work

Post by BenR »

Hi Bob,

It should round for you.

so 1.56 with 1 DP would display as 1.6

Post Reply