Page 1 of 1

fround does not appear to work

Posted: Sun Nov 13, 2022 11:04 pm
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 2868 times
RPI_EcoEyeMonitor_V1_4A.fcfx
(37.95 KiB) Downloaded 320 times
Bob

Re: fround does not appear to work

Posted: Mon Nov 14, 2022 1:14 am
by RGV250
Also tried without the space between the "fround" and the bracket, still no good.

Re: fround does not appear to work

Posted: Mon Nov 14, 2022 8:29 am
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

Re: fround does not appear to work

Posted: Mon Nov 14, 2022 12:34 pm
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

Re: fround does not appear to work

Posted: Mon Nov 14, 2022 12:53 pm
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.

Re: fround does not appear to work

Posted: Mon Nov 14, 2022 1:07 pm
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

Re: fround does not appear to work

Posted: Mon Nov 14, 2022 3:15 pm
by BenR
Hi Bob,

It should round for you.

so 1.56 with 1 DP would display as 1.6