Home Segments Index Top Previous Next

494: Mainline

To implement the formatWithWidth:andFraction: method, you need the truncated method. Whenever it is sent to a Float instance, the truncated method answers with an Integer instance equal to the truncated Float instance:

Workspace
Transcript show: 3.14159 truncated printString 
Transcript 
3 

Using truncated and abs, the method that produces the absolute value of a number, you can produce the fraction portion of a floating-point number:

Transcript show: (3.14159 truncated - 3.14159) abs printString; cr; 
           show: (-3.14159 truncated - -3.14159) abs printString; cr 
Transcript 
0.14159 
0.14159