Floating-point

General discussion on mikroC.
Post Reply
Author
Message
marco
Posts: 57
Joined: 03 Jan 2008 20:34

Floating-point

#1 Post by marco » 01 Oct 2010 16:18

Hello again my friends!

I´m having some difficulties to solve this problemes.
i´m reading from ADC 10bits , and i want to do this simple operation !

Ex: ADC value = 700;

700/120=5,83333333

I want to read 5,83333333 but instead i only read 5 !

Or:
51*3.14=160,14 but instead i only read 160

I want to read and write Floating-point numbers.

Can anyone healp me?

Thanks

Sparky1039
Posts: 1179
Joined: 24 Nov 2005 20:07
Location: Colorado, USA

Re: Floating-point

#2 Post by Sparky1039 » 01 Oct 2010 18:31

Have you created a variable that accepts floating point values... i.e "float myVar" ?

Might be simpler to use interger math.

Code: Select all

unsigned long tempVal = 0;
unsigned char integer = 0;
unsigned int decimal = 0;

tempVal = (adcIn * 1000) / 120; // (700 * 1000) / 120 = 5833

integer = tempVal / 1000; // = 5
decimal = tempVal % 1000; // = 833
then just print the results like
LCD print integer
LCD print "."
LCD print decimal

... to give you 5.833

marco
Posts: 57
Joined: 03 Jan 2008 20:34

Re: Floating-point

#3 Post by marco » 05 Oct 2010 13:37

As always a simple and perfect answer !!

Thank you again for the great help my friends.

Post Reply

Return to “mikroC General”