Page 1 of 1
float number rounding
Posted: Mon Mar 08, 2010 1:52 pm
by Ondra
Can someone advise how to do rounding on float numbers?
I don't see a rounding function under the calculation Icons list of functions.
Ondra
Re: float number rounding
Posted: Mon Mar 08, 2010 1:59 pm
by Steve
Re: float number rounding
Posted: Mon Mar 08, 2010 2:45 pm
by Ondra
When I tried the code below I got a compile error. I have attached my file, have a look.
Ondra
C:\Documents and Settings\Ondra\Desktop\Pebble 8_Dec24_09\Test programs\Sensor_distance calulator v4.c(495): error: can't convert 'int32' to 'float'
C:\Documents and Settings\Ondra\Desktop\Pebble 8_Dec24_09\Test programs\Sensor_distance calulator v4.c(495:22): error: failed to generate expression
Sensor_distance calulator v4.c success
failure
Return code = 1
Flowcode was unable to compile the flowchart's C code due to the following errors:
If your flowchart contains C code, please review this carefully. If your flowchart contains no C-code or you have thoroughly reviewed the code, contact Technical Support.
Re: float number rounding
Posted: Mon Mar 08, 2010 3:42 pm
by Benj
Hello Ondra
This problem is related to the round function. For some reason this is not generating C code correctly so I will look into this for you.
As a workaround you can use C code for now which will allow you to compile. Unfortunatley it will no longer simulate the round function.
The C code for the round command in your program should look like this.
FCV_FLT_FOOT_INCHES = float32_round_to_int(FCV_FLTVAL);
Before you call the C command you can also specify the following in C.
float_rounding_mode = X;
where X =
float_round_nearest_even = 0
float_round_down = 1
float_round_up = 2
float_round_to_zero = 3
I have attached an updated version of your program that should compile correctly now.