开发者

Polarized shift of percentage values

开发者 https://www.devze.com 2022-12-15 18:14 出处:网络
differencePercentage = Math.round(((Pay.init / Pay.curr开发者_如何学Cent) * 100) - 100); and that gives me the difference in percent between initial and current pay, but it\'s reversed. When it\'s po

differencePercentage = Math.round(((Pay.init / Pay.curr开发者_如何学Cent) * 100) - 100);

and that gives me the difference in percent between initial and current pay, but it's reversed. When it's positive i.e. pay is above the initial value it says -X%, and when it's below it says X%.

Is there any obvious way I'm not seeing to polarize this?

Thanks for any insight. :)


differencePercentage = Math.round(100 - ((Pay.init / Pay.current) * 100));

[-(a - b) = -a + b = b - a]

Also:

differencePercentage = Math.round(100 * (1 - (Pay.init / Pay.current)));


differencePercentage = Math.round(((Pay.current / Pay.init) * 100) - 100);

0

精彩评论

暂无评论...
验证码 换一张
取 消