Sir I am trying to use the fround command to limit a floating variable to 2 decimal places. It appears not to work in the simulation.
EMA_APHIA = 0.90
EMA_APHIA = fround (EMA_APHIA,2)
when I run the simulation I get 0.899999976------------lots more.
Does this command work in the simulation or only once complied?
While my program is not yet complete as I test each part as I go I have attached the flowcode file MAP_4CH_24FV_master_slave.fcfx
I have read the articles on the forum that tend to indicate the command does not work on 16bit PIC chips.
Can someone please enlighten me as to what I am doing wrong.
Thanks
fround command pic 24fFV
Moderator: Benj
-
- Flowcode V4 User
- Posts: 17
- Joined: Thu Jul 30, 2009 9:13 am
- Location: New Zealand
- Been thanked: 1 time
fround command pic 24fFV
- Attachments
-
- MAP_4CH_24FV_master_slave.fcfx
- (35.67 KiB) Downloaded 38 times
Regards
Roy
Roy
-
- Valued Contributor
- Posts: 1200
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: fround command pic 24fFV
One way to do this is to multiply the value by 100 (for 2 decimal places) and assign to an integer...
Note that not all numbers can be represented exactly by fp variables.
Can I also suggest an upgrade to v10 it's free and v4 is now very old
Martin
Note that not all numbers can be represented exactly by fp variables.
Can I also suggest an upgrade to v10 it's free and v4 is now very old
Martin
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: fround command pic 24fFV
Please keep in mind computers work in ones and zeros, not floating point numbers. As a result some floating point numbers can not be represented exactly and are a close approximation. Check https://floating-point-gui.de/ for an easy explanation or https://ece.uwaterloo.ca/~dwharder/Num ... /paper.pdf for the heavy theory.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- Flowcode V4 User
- Posts: 17
- Joined: Thu Jul 30, 2009 9:13 am
- Location: New Zealand
- Been thanked: 1 time
Re: fround command pic 24fFV
Thanks for your comments . I am using version V8.
I would like to use the value in an EMA calculation (1-alhpia) as part of a filter.
It seems to work in my 8 bit version of the program.
I would like to use the value in an EMA calculation (1-alhpia) as part of a filter.
It seems to work in my 8 bit version of the program.
Regards
Roy
Roy
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: fround command pic 24fFV
Calculations with the numbers should be fine, it is just displaying for us humans that doesn’t work as expected.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis