Avoid (double) divide-by-zero.
On startup, maxValue may be 0 (e.g. for auto-adjusting sensors) and then we get a divide-by-zero. In practice this hammers the resulting integer to negative-biggity, but it's still undefined behavior. Just use 0 instead. While here, massage the C-style cast as well. Make the whole ternary expression a double, then cast.
Showing with 2 additions and 2 deletions