ArithmeticValue.st
changeset 19056 b6e142aad476
parent 18860 fb68af2a33a9
child 19064 a091c7289e0e
child 19454 895593647d58
equal deleted inserted replaced
19055:2d415d3c14fe 19056:b6e142aad476
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1993 by Claus Gittinger
     2  COPYRIGHT (c) 1993 by Claus Gittinger
     5 	      All Rights Reserved
     3 	      All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
  1545 !
  1543 !
  1546 
  1544 
  1547 truncateTo:aNumber
  1545 truncateTo:aNumber
  1548     "return the receiver truncated to multiples of aNumber"
  1546     "return the receiver truncated to multiples of aNumber"
  1549 
  1547 
  1550     ^ ((self / aNumber) floor * aNumber) asInteger
  1548     |t|
       
  1549     
       
  1550     aNumber <= 0 ifTrue:[self error:'argument must be positive'].
       
  1551     
       
  1552     t := (self / aNumber) floor * aNumber.
       
  1553     (aNumber isInteger) ifTrue:[
       
  1554         ^ t asInteger
       
  1555     ].    
       
  1556     ^ t
       
  1557 
       
  1558     "
       
  1559      truncate to multiples of 4 
       
  1560         123.456 truncateTo:4
       
  1561         124.456 truncateTo:4
       
  1562      truncate to multiples of 2 
       
  1563         122.456 truncateTo:2
       
  1564         123.456 truncateTo:2
       
  1565         124.456 truncateTo:2
       
  1566      normal truncate
       
  1567         123.456 truncateTo:1
       
  1568         124.456 truncateTo:1
       
  1569      truncate to decimal digits    
       
  1570         123.456 truncateTo:0.1
       
  1571         123.987 truncateTo:0.1
       
  1572         123.456 truncateTo:0.01
       
  1573     "
  1551 !
  1574 !
  1552 
  1575 
  1553 truncated
  1576 truncated
  1554     "return the receiver truncated towards zero"
  1577     "return the receiver truncated towards zero"
  1555 
  1578