Hi Guys
I'm trying to display percentage on my LCD display the formula I'm using is Percentage = ((DutyCycle / 255) * 100) what happens it will display 100% (255 / 255) * 100 but will not display any other value eg Percentage = (( 253 / 255) * 100 ) which should give me 99.21 % except it gives me 0%, Percentage is a floating variable. Any ideas what I'm doing wrong
Percentage
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: Percentage
You need to force use of FP numbers so "253.0 /255 * 100" should work. It's currently calculated as an integer then converted on assignment. (note the .0 does the magic)
Martin
Martin