Are A and B integers? If so the reason you are getting zero is because the compiler is doing integer math. You have to use "casting". Try doing it this way instead: ((float)A)/B * 100.0. While this doesn't look like it is any different from what you are doing it most certainly is. The (float) tells the compiler to treat A as a float (even though it is an integer) and the compiler converts the A to a float. Then it sees the division, since A is a float the division must be done with two floats, so the compiter converts B to a float as well, and then does the division, with the result being a float. The 100.0 isn't really necessary but it does give a hint to what you are doing if someone else is reading your code. Please note that I don't have that compiler, I'm simply speaking about standard ANSI C, I'm sure that compiler has these features. TTYL > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Rich Mcelroy > Sent: Friday, February 22, 2002 10:48 > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]:MPLAB floating point in C > > > I'm using Bytecraft's compiler for MPLAB. it does basic math, but the > results I'm getting indicate that it is droping anything after the integer > on my calculations. I'm trying to calculate a percentage: > > Percent = A/B * 100; something like that. I have been getting a zero for > percent everytime. > > -----Original Message----- > From: Dale Botkin [mailto:dale@BOTKIN.ORG] > Sent: Friday, February 22, 2002 9:22 AM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]:MPLAB floating point in C > > > What are you trying to do? Float <--> integer conversion is just a matter > of casting, and I haven't seen a C compiler recently that didn't support > basic operations (+,-,/,*). Standard C math functions will do a lot... > are you using a compiler without floating point support? > > Dale > -- > "Curiosity is the very basis of education and if you tell me that > curiosity killed the cat, I say only the cat died nobly." > - Arnold Edinborough > > > On Fri, 22 Feb 2002, Rich Mcelroy wrote: > > > Does anyone have math libraries for using floating point variables in c. > I > > am working on a PIC and I have seen microchip's AN575. That > would be very > > useful if the application I was working with was in asm. I have looked > all > > over for help on doing this in c. Maybe someone here can help. Thanks > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > > -- > http://www.piclist.com hint: The list server can filter out subtopics > (like ads or off topics) for you. See http://www.piclist.com/#topics > > > -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics