How to calculate percentage when old value is ZERO

后端 未结 9 981
甜味超标
甜味超标 2021-01-31 16:20

I need the logic for the following situation. I am clueless in doing this.

Consider for January I have 10$ revenue and f

9条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 17:01

    There is no rate of growth from 0 to any other number. That is to say, there is no percentage of increase from zero to greater than zero and there is no percentage of decrease from zero to less than zero (a negative number). What you have to decide is what to put as an output when this situation happens. Here are two possibilities I am comfortable with:

    1. Any time you have to show a rate of increase from zero, output the infinity symbol (∞). That's Alt + 236 on your number pad, in case you're wondering. You could also use negative infinity (-∞) for a negative growth rate from zero.
    2. Output a statement such as "[Increase/Decrease] From Zero" or something along those lines.

    Unfortunately, if you need the growth rate for further calculations, the above options will not work, but, on the other hand, any number would give your following calculations incorrect data any way so the point is moot. You'd need to update your following calculations to account for this eventuality.

    As an aside, the ((New-Old)/Old) function will not work when your new and old values are both zero. You should create an initial check to see if both values are zero and, if they are, output zero percent as the growth rate.

提交回复
热议问题