Thread Tools Display Modes
01-24-12, 11:23 AM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Math Help

I have a number, its a money value, I need to subtract 20% from it. how would you do that? then display the new number? since i cant use %'s
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-24-12, 11:31 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
20% is the same as 0.20 so multiply by 0.x for any percentage to get the percentage amount then deduct it from the original amount.


There is another way to get the result straight off but the above is the simplest method.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
01-24-12, 11:52 AM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
money*0.8

All the money functions return copper amount.

So just use amount * 0.8 (that's 80%) then format it to gold silver copper with one of the built-in functions.

(can look it up, don't remember it off-hand)
  Reply With Quote
01-24-12, 12:30 PM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
ah thats it ... result = ( money * ( 1 - (percent/100) )

if percent is 20 then this would come out as

(money * ( 1 - (20/100))
(money * ( 1 - 0.2))
(money * 0.8)

It would then work for any percentage you need.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
01-24-12, 12:51 PM   #5
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
This produced proper results -
Code:
GameTooltip:AddDoubleLine("Friendly Discount", addon:MoneyToString(floor(totalCost * 0.95), true))
	GameTooltip:AddDoubleLine("Honored Discount", addon:MoneyToString(floor(totalCost * 0.9), true))
	GameTooltip:AddDoubleLine("Revered Discount", addon:MoneyToString(floor(totalCost * 0.85), true))
	GameTooltip:AddDoubleLine("Exaulted Discount", addon:MoneyToString(floor(totalCost * 0.8), true))
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-25-12, 12:40 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Xrystal View Post
20% is the same as 0.20 so multiply by 0.x for any percentage to get the percentage amount then deduct it from the original amount.
What kind of schools are people attending where they don't learn about percents?
  Reply With Quote
01-25-12, 03:20 AM   #7
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
One of the best things when it comes to percentages is the "Dreisatz" (rule of proportion).

http://en.wikipedia.org/wiki/Rule_of_proportion

So easy example. You have 100$. That is 100% of your money. You want so substract 20% of it. So you can write down:
Code:
100$     x
----  =  ---
100%     80%
x is the value you want to calculate and it is 100%-20% = 80% of your money.

Now all you have to do is to make the value for x come out. (Having x stand on one side)

To make that possible you multiplay both side of the equation with 80%. By doing that the 80% on the right side will fade because 80% / 80% is 1.

Code:
100$*80%      x*80%
--------   =  ---
100%          80%

100$*80%      x*1
--------   =  ---
100%          1

100$*80%      
--------   =  x
100%
Result:

Code:
x = 100$*80%/100%

x = 80$
The cool thing about that is that even the suffixes come out accordingly. The % delete themselve only the $ stays. Btw. 8000/100 is the same as 100*0.8. Doesn't matter.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 01-25-12 at 03:36 AM.
  Reply With Quote
01-25-12, 01:44 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I have never, ever seen that method using proportions before, Zork.

(At least in America) we teach that this is how to use proportions to solve percent problems.

Code:
 percent     portion 
--------- = ---------
   100        whole
so, let's say you want 80% of 200:
Code:
 80       x  
----- = -----
 100     200
Then you cross-multiply
Code:
80 * 200 = 100 * x
divide by 100 on both sides to solve for x
Code:
( 80 * 200 ) / 100 = 100x / 100
160 = x

(I'm a math teacher.)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
01-25-12, 03:54 PM   #9
Ither
A Firelord
 
Ither's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 497
Originally Posted by Seerah View Post
I have never, ever seen that method using proportions before, Zork.
No disrespect, but that's because you're American?

Dreisatz is taught at realschulen (secondary school) in many European countries. I learned it and I live in Germany, well did until I moved to America.
__________________
  Reply With Quote
01-25-12, 05:52 PM   #10
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,934
It's been a long while since I did basic maths in school in the UK but Seerah's way did look a lot more familar than Zorks. But then again things can change in 30 years rofl.

The way I mentioned was from my time as an accountancy software programmer. We had to use formulae like that all the time to get tax and discount calculations right.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Math Help


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off