conditional commission rate formula

I'm trying to figure out how to make a formula to solve this problem:

Say that you get paid commission based on how much you sell. If you sell anywhere from \$0 to \$5000, you get a commission rate of 8%. If you sell anywhere from \$5000.01 to \$10,000, you get a rate of 10%. Anything above \$10,000 gets a rate of 12%. The trick comes with how the interest is applied. For example, if you sold$15,000:

the first $5000 gets %8 the second$5000 gets %10
and the third $5000 would get %12  resulting in (5000 * 0.08) + (5000 * 0.10) + (5000 * 0.12) = 1500  Is there a way to create a formula for this? Also, I tagged this as linear algebra as I figure the formula will be algebraic, but I don't actually know what to tag this as. - 1 Answer$x = $Total Sold Profit Earned$= \min(x,5000)*0.08+\max(\min((x -5000),5000),0)*0.1+\max((x-10000),0)*0.12\$

-
thanks so much! –  LordZardeck Oct 17 '12 at 19:43