System.Math.RoundTo

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

const ADigit: TRoundToEXRangeExtended): Extended;

C++

extern DELPHI_PACKAGE System::Extended __fastcall RoundTo(const System::Extended AValue, const TRoundToEXRangeExtended ADigit);

Properties

Type Visibility Source Unit Parent
function public
System.Math.pas
System.Math.hpp
System.Math System.Math

Description

Rounds a floating-point value to a specified digit or power of ten using "Banker's rounding".

Call RoundTo to round AValue to a specified power of ten.

AValue is the value to round.

ADigit indicates the power of ten to which you want AValue rounded. It can be any value in the range from –20 through 20.

RoundTo uses "Banker's Rounding" to determine how to round values that are exactly midway between the two values with the desired number of significant digits. This method rounds to an even number if AValue is not nearer to either value.

The following examples illustrate the use of RoundTo:

Expression

Value

RoundTo(1234567, 3)

1235000

RoundTo(1.124, -2)

1.12

RoundTo(1.125, -2)

1.12

RoundTo(1.126, -2)

1.23

Attention: Binary numbers cannot represent decimal real-numbers exactly. You may not get the expected result if Digit is a negative number. For example, the decimal real-number, "1.245" is represented as "1.245000000000000106..." in Double-type floating-point numbers. RoundTo(1.245, -2) will return 1.25, not 1.24, because the number is larger than exactly midway between the two values that have the desired number of significant digits.


See Also