Programmer's Reference

ScaledDecimal

The ScaledDecimal class represents fixed point decimal data exactly with precisions of up to 31 digits. It also performs the arithmetic on such data when combined with any other numeric type.

Decimals are represented as in the following example:

3.4s

The number is interpreted as having a value of 3.4, with a precision of 2 digits, and a scale of 1. Precision is defined as the number of digits. Scale is defined as the number of digits needed to represent the fractional part.

Instances of ScaledDecimal can be used in normal Smalltalk arithmetic operations. Scaled Decimals are considered to be higher in generality than Integers and Fractions but lower than Floats. For example:

3.4s + 1.0 ==> 4.4 (Float)
3.4s + ( 1/3 )  ==> 3.73333333333333333333333333333d30.29 (Decimal)

Precisions and scales do not follow the same arithmetic rules as values. For example:

Precision = 3              Precision = 2            Precision = 4
Scale = 2                  Scale = 1                Scale = 2
9.99s  +  2.3s =  12.29s

Converting

asScaledDecimal, asFloat, asFraction, asInteger

Accessing

fractionPart, integerPart, scale, significantDigits

Printing

printOn:showDigits:Pad:

Creating instances

fromString:

The DM application also provides the method asScaledDecimal to the class String. The following illustrates two ways of creating the same ScaledDecimal:

'3.4' asScaledDecimal
ScaledDecimal fromString: '3.4'


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]