1
2
11
12
19 class com.sekati.math.RuleOf3 extends Number {
20
21 private var _n:Number;
22
23
31 public function RuleOf3(partialValue:Number, totalValue:Number, partialPercent:Number, totalPercent:Number, zeroPercentValue:Number) {
32
33 if (zeroPercentValue == null) {
34 zeroPercentValue = 0;
35 }
36
37 if (partialValue == null) {
38
39 _n = ((totalValue - zeroPercentValue) * partialPercent / totalPercent) + zeroPercentValue;
40 return;
41 } else if (totalValue == null) {
42
43 _n = ((partialValue - zeroPercentValue) * totalPercent / partialPercent) + zeroPercentValue;
44 return;
45 } else if (partialPercent == null) {
46
47 _n = ((partialValue - zeroPercentValue) * totalPercent) / (totalValue - zeroPercentValue);
48 return;
49 } else if (totalPercent == null) {
50
51 _n = ((totalValue - zeroPercentValue) * partialPercent) / (partialValue - zeroPercentValue);
52 return;
53 }
54
55 throw new Error( "@@@ com.sekati.math.RuleOf3 Error: could not calculate faulty arguments." );
56 }
57
58
62 public function valueOf():Number {
63 return _n;
64 }
65
66
70 public function toString():String {
71 return _n.toString( );
72 }
73 }