Understanding Division in Arduino C language

Greetings, mighty hackers.

Can someone explain why the result of this Serial.println(77/99); is 0, instead of a number between 0 and 1?

I'm guessing / means integer division? How do I divide in a full (non integer way)?

Many thanks

First, it is not "Arduino C language", it is c language. Period. It is exactly the same as any other c language.

Google integer arithmetic. By definition, integers are whole numbers only: 1, 2, 3, etc. If you want a floating point result, use floating point variables. But the arithmetic will be much slower, and consume much more memory, both FLASH and RAM.

Regards, Ray L.

Try using 77.0/99.0

That tells the compiler that the constants are floating point, not integers.

aimaty: Can someone explain why the result of this

Serial.println(77/99);

is 0, instead of a number between 0 and 1?

All math operations in C are dependend on type and follows the C rules.

int / int = int

So the result is a whole number (int) only.

To create a float division you need either dividend or divisor to be a float number: int / float = float float / int = float

So "77.0/99" would result in a float number. Or "77/99.0" would also result in a float number.

Many thanks to Lord Vader and to jurs, understood those usefull explanations.

I'm not into programming, I like to build circuits and study electronics, but dealing with the arduino is giving me headaches due to C.

What language are you coming from?

I've studied pascal and C, but I've forgotten stuff. My brain discards everything it doesn't like, it's tough.