Help with variable type in EasyC.

I would like to display the value of a variable in EasyC as a number with a decimal point and 1 to 2 digits to the right ( x.x or x.xx ).

I’m just not sure what variable type to set the variable as. I know it’s not an interger. I tried looking in the help files, but that really didn’t help me.

If someone could let me know how to do this, I would really appreciate it. If this question has been answered in a previous thread, I apologize for not searching the forum for it.


I am not very familiar with EasyC, but in other programming languages, you would use a double or a float. To get 1 or 2 decimal places, you would need to round the variable and possible have to convert it to a string and remove the last very characters.

You can use either a float or double.

Well, that is a Problem…

You want the “float” or “double” data type.

Under EasyC and MCC18, they are the exact same size in Bits, 32, and have the same Precision. Most other ‘C’ Compilers, they are different sizes and Precisions.

The Problem is, the PrintToScreen in EasyC and the printf in MCC18 don’t print “float” or “double” data types.

So, you have some choices…

  1. Use the “float” or “double” data type, and write your own PrintToScreen for EasyC or printf for MCC18.

  2. Use Fixed Point values in integer variables.

I have posted a Programming Example:

Using Fixed Point values in Integer Variables.

Thanks everyone for the help, - especially MarkO!

I didn’t realize it would be that much of a problem or that I wouldn’t be able to print it to the screen. All I figured I would need to do is to set the proper variable type.

I just wanted to be able to eventually display the voltage of the battery connected to my Power Expander on the VEX LCD that’s coming out.

I really appreciated the EasyC code that MarkO posted. It was a lot of help - I learned some new things and now I know how to do it!

Thanks again,

Your Welcome…

I think I will “enhance” the documentation a little more… I was in a hurry and just “threw it together”.

I chose EasyC 1.x, because it is “the Least Common Denominator”, in that in can be converted to any version of EasyC, easily… :wink: