|
Truncating or rounding displayed variables Anonymous |
11 year
|
Hi ,
I am measuring small objects under a microscope with RR, and displaying the results with wither the 'display Text' function or 'display variables' functions.
The Variables are being manipulated in the C interpretor and are written out with the setFloatVariable command.
Is there an easy way of truncating or removing decimal places from the displayed variables (without turning them to 'int' alltogether).
eg to display 45.323131 as 45.32?
many thanks,
Bernard
|
|
|
Carl from Your Country [1447 posts] |
11 year
|
Bernard,
Yes, if you use something like
x = (float)((int)(x*100.0f))/100.0f;
that will round the number to 2 decimal places. Is that what you need?
STeven.
|
|
|
Anonymous |
11 year
|
Hi Steven,
THanks for your reply.. That did something....
I had to remove the 'f's after the 100.0 to get it to run.
It now displays the number as follows... 45.320000
but sometimes as 45.320001 or 45.319999.
It would be nice to be able to remove the extra zeros...
Bernard
|
|
|
Carl from Your Country [1447 posts] |
11 year
|
Bernard,
You can force it into a string to specify exactly how many decimal points you see. Assuming the CScript module use
float x = 5.12345;
x = ((int)(x*100.0))/100.0;
char buffer[32];
sprintf(buffer, "%f", x);
setStrVariable("x", buffer);
to force it to display X as a string instead of a float.
STeven.
|
|