TimothyMoulder
Member
Does anybody know a clever way of using integers to calculate a percentage to display on an HMI, to the first decimal point?
The display I'm using (exor) can use a fixed decimal point, so an integer of 101 can be displayed as 10.1%
The best I've been able to manage is :
x = fail count
y = sum of all parts
z = integer
(x*1000) / y = z
example : (7*1000) / 19 = 368 (36.8%)
The problem? If you get more than 32 failures, the product of the first multiplication will overflow the integer and fault.
Yes, I know about long integers, ala AB, and double words on some other processors, but I want something general enough to be used anywhere, including processors without those features.
Besides, long integers have't been around that long, relatively-speaking. Somebody has to have found a way to do this before, using integers only.
Thanks!
TM
The display I'm using (exor) can use a fixed decimal point, so an integer of 101 can be displayed as 10.1%
The best I've been able to manage is :
x = fail count
y = sum of all parts
z = integer
(x*1000) / y = z
example : (7*1000) / 19 = 368 (36.8%)
The problem? If you get more than 32 failures, the product of the first multiplication will overflow the integer and fault.
Yes, I know about long integers, ala AB, and double words on some other processors, but I want something general enough to be used anywhere, including processors without those features.
Besides, long integers have't been around that long, relatively-speaking. Somebody has to have found a way to do this before, using integers only.
Thanks!
TM