Arduino Forum
>
Forum 20052010 (read only)
>
Software
>
Syntax & Programs
>
Simple integer division question
Print
Go Down
Pages:
[1]
Topic: Simple integer division question
(Read 9835 times)
previous topic

next topic
ADJ_ADT
Guest
Simple integer division question
Nov 13, 2009, 08:34 pm
Apologies for such a basic question  I haven't been able to find an answer anywhere.
I'm wondering how Arduino handles fractions of integers.
I'm using Arduino to run a 12 bit TLV5618 DAC (04095)  when I set the output value to, for example, 4095/2  am I getting 2047.5 or does Arduino round it up/down to a 'whole' integer?
If it is actually a fraction  how many decimal places would it go to?
Hope that makes sense  thanks.
J
PaulS
Brattain Member
Posts: 82,036
Karma: 2339
[add]
Seattle, WA USA
Re: Simple integer division question
#1
Nov 13, 2009, 09:19 pm
If the numerator is an integer, and the denominator is also an integer, the result will be an integer, too. In integer division, any fractional part is truncated. There is no rounding.
The art of getting good answers lies in asking good questions.
ADJ_ADT
Guest
Re: Simple integer division question
#2
Nov 13, 2009, 09:29 pm
Thanks Paul  that's excellent.
So 2047.5 would be truncated to 2047 and 912.3127 would be truncated to 912?
Appreciated.
J
mathieujofis
Guest
Re: Simple integer division question
#3
Nov 15, 2009, 06:57 pm
yes
Print
Go Up
Pages:
[1]
Loading...