Number.st
branchjv
changeset 19707 8e312f358d84
parent 19478 1f5aa87f6170
parent 19702 79ea925e1f35
child 19811 65fec19facb0
--- a/Number.st	Wed May 04 06:50:56 2016 +0200
+++ b/Number.st	Thu May 05 06:48:19 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,19 @@
     ^ self.
 !
 
+asPercentFrom:fullAmount
+    "what is the percentage
+     taking the receiver's value from the argument"
+    
+    ^ (self / fullAmount) * 100.
+
+    "
+     20 asPercentFrom:100
+     (10 asPercentFrom:156) asFixedPoint:2
+     (15.6 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 +1125,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"