Instead of dividing by (maxhealth/curhealth), multiply by (curhealth/maxhealth).
When curhealth reaches zero, maxhealth/curhealth tries to perform a divide-by-zero operation.
The math is
Screen width
multiplied by
cur divided by max
Cur divided by max can “never” be more than one or less than zero, so you’ll get a percentage of screen width back. At cur=0, you’ll get 0; at cur=max, you’ll get 100% of screen width.