Loading...
Pages: [1]   Go Down
Author Topic: Simple integer division question  (Read 1103 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 (0-4095) - 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
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 314
Posts: 35519
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Paul - that's excellent.

So 2047.5 would be truncated to 2047 and 912.3127 would be truncated to 912?

Appreciated.

J
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes
Logged

Pages: [1]   Go Up
Print
 
Jump to: