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.
Bob
fround does not appear to work
-
- Posts: 283
- http://meble-kuchenne.info.pl
- Joined: Sat Mar 19, 2022 4:53 pm
- Has thanked: 25 times
- Been thanked: 32 times
-
- Matrix Staff
- Posts: 1913
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 621 times
- Been thanked: 644 times
Re: fround does not appear to work
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
Use
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
Code: Select all
Sensor_1_Power = Sensor_1_Current * 240.0 / 100000.0
Martin
Re: fround does not appear to work
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
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
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 501 times
- Been thanked: 686 times
Re: fround does not appear to work
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Re: fround does not appear to work
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
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
-
- Matrix Staff
- Posts: 1926
- Joined: Mon Dec 07, 2020 10:06 am
- Has thanked: 501 times
- Been thanked: 686 times
Re: fround does not appear to work
Hi Bob,
It should round for you.
so 1.56 with 1 DP would display as 1.6
It should round for you.
so 1.56 with 1 DP would display as 1.6
Regards Ben Rowland - MatrixTSL
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel
Flowcode Online Code Viewer (Beta) - Flowcode Product Page - Flowcode Help Wiki - My YouTube Channel