Send feedback on this topic.
Teradata.Client.Provider
AdjustScale Method
Example 



Teradata.Client.Provider Namespace > TdDecimal Structure : AdjustScale Method
The TdDecimal whose scale will be adjusted.
The number of digits that will be added to the scale and precision.
Indicates whether the number will be rounded after being adjusted.
The scale of the TdDecimal operand will be adjusted to the number of digits indicated by the digits parameter.
Syntax
'Declaration
 
Public Shared Function AdjustScale( _
   ByVal input As TdDecimal, _
   ByVal digits As Integer, _
   ByVal round As Boolean _
) As TdDecimal
'Usage
 
Dim input As TdDecimal
Dim digits As Integer
Dim round As Boolean
Dim value As TdDecimal
 
value = TdDecimal.AdjustScale(input, digits, round)
public static TdDecimal AdjustScale( 
   TdDecimal input,
   int digits,
   bool round
)
public:
static TdDecimal AdjustScale( 
   TdDecimal input,
   int digits,
   bool round
) 

Parameters

input
The TdDecimal whose scale will be adjusted.
digits
The number of digits that will be added to the scale and precision.
round
Indicates whether the number will be rounded after being adjusted.

Return Value

A TdDecimal that contains the result is returned.
Exceptions
ExceptionDescription
Either the Precision of TdDecimal will be greater than the MaxPrecision, or the integer part of TdDecimal will be affected by this operation.
The new scale will cause an illegal truncation of TdDecimal.
Either the precision or scale is out of Range.
The value of digits will cause an invalid adjustment to be made.
Remarks
digits can be either be a positive or negative number. The number passed in for digits will affect both the precision and scale. The value of digits is added to the Precision and Scale of the TdDecimal.

Therefore, digits cannot exceed "MaxPrecision – Precision". For example, if the Precision of the TdDecimal is 20 then digits cannot be greater than 38 – 20 = 18. If digits were greater than 18, the TdDecimal will have a precision greater than the MaxPrecision.

In addition, if a negative value is specified for digits, the absolute value cannot exceed the Scale of the TdDecimal. For example, if the TdDecimal has a Scale of 5, the value of digits cannot be less than -5. A value that is less indicates that the integer part of the decimal (the numbers to the left of the decimal point) is to be either rounded or truncated. AdjustScale does not allow the integer part of the decimal to be rounded or truncated.

Depending upon the value of the round parameter, the value will either be rounded to the appropriate number of digits or truncated. If fRound is true, the TdDecimal will be rounded. false the value will be truncated.
Example
The following is an example of the use of AdjustScale:
//The M is used to indicate that the numeric literal is a System.Decimal
 
//Precision = 12, Scale = 5
TdDecimal decimal1 = new TdDecimal(3243167.43633M);
 
// newDecimal1 = 3243167.43633, Precision = 15, Scale = 8
TdDecimal newDecimal1 = TdDecimal.AdjustScale(decimal1, 3, false);
 
// newDecimal2 = 3243167.43, Precision = 9, Scale = 2
//   Result was truncated.
TdDecimal newDecimal2 = TdDecimal.AdjustScale(decimal1, -3, false);
 
// newDecimal2 = 3243167.44, Precision = 9, Scale = 2
//   Result was rounded.
TdDecimal newDecimal2 = TdDecimal.AdjustScale(decimal1, -3, true);
 
// A TdException will be thrown because the value passed in for the
// digits parameter will affect the integer part of the decimal number.
TdDecimal newDecimal2 = TdDecimal.AdjustScale(decimal1, -7, true);
Requirements

Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019

See Also

Reference

TdDecimal Structure
TdDecimal Members