#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Wed, 04 May 2016 17:51:54 +0200
changeset 19701 92aff12989fa
parent 19700 3775538c52dc
child 19702 79ea925e1f35
#FEATURE by cg class: Number added: #asPercentFrom: #percentOf:
Number.st
--- a/Number.st	Wed May 04 12:22:31 2016 +0200
+++ b/Number.st	Wed May 04 17:51:54 2016 +0200
@@ -503,7 +503,6 @@
     ^ Integer readFrom:aStream radix:radix
 ! !
 
-
 !Number class methodsFor:'constants'!
 
 decimalPointCharacter 
@@ -934,7 +933,6 @@
     ^ self rounded printString
 ! !
 
-
 !Number methodsFor:'coercing & converting'!
 
 i
@@ -1056,6 +1054,17 @@
     ^ self.
 !
 
+asPercentFrom:hundredPercent
+    "how many percent is the receiver of the argument"
+    
+    ^ (self / hundredPercent) * 100.
+
+    "
+     20 asPercentFrom:100
+     (10 asPercentFrom:156) asFixedPoint:2
+    "
+!
+
 asPoint
     "return a new Point with the receiver as all coordinates;  
      often used to supply the same value in two dimensions, as with 
@@ -1114,6 +1123,18 @@
     "Modified: 22.4.1996 / 13:00:27 / cg"
 !
 
+percentOf:hundredPercent
+    "how many is self-percent from the argument"
+    
+    ^ (hundredPercent / 100 * self)
+
+    "
+     20 percentOf:100
+     (10 percentOf:156) asFixedPoint:2
+     (105 percentOf:156) asFixedPoint:2
+    "
+!
+
 radiansToDegrees
     "interpreting the receiver as degrees, return the radians"