float number rounding

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

float number rounding

Post 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

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: float number rounding

Post by Steve »

Code: Select all

float1 = round( float2 )

Ondra
Posts: 325
Joined: Wed Aug 29, 2007 7:33 pm
Been thanked: 2 times
Contact:

Re: float number rounding

Post 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.
Attachments
Sensor_distance calulator v4.fcf
(12.75 KiB) Downloaded 270 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: float number rounding

Post 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.
Attachments
Sensor_distance calulator v4.fcf
(14 KiB) Downloaded 291 times

Post Reply