Pascal Tips Homepage  •  Privacy Policy & Imprint

FreePascal Unit SysUtils

Miscellaneous Conversion Routines

SysUtils unit, section Conversion Routines.
Every function name links to its original documentation page.

BCDToInt

function BCDToInt(Value: Integer): Integer;

Converts a BCD (Binary Coded Decimal) coded integer to a normal integer representation.

CompareMem

function CompareMem(P1: Pointer; P2: Pointer; Length: PtrUInt): Boolean;

Compares two memory regions byte by byte for the specified length and returns True if all bytes are identical, False otherwise.

FloatToStrF

function FloatToStrF(Value: Extended; format: TFloatFormat; Precision: Integer; Digits: Integer): string;
function FloatToStrF(Value: Extended; format: TFloatFormat; Precision: Integer; Digits: Integer; const FormatSettings: TFormatSettings): string;
function FloatToStrF(Value: Double; format: TFloatFormat; Precision: Integer; Digits: Integer): string;
function FloatToStrF(Value: Double; format: TFloatFormat; Precision: Integer; Digits: Integer; const FormatSettings: TFormatSettings): string;
function FloatToStrF(Value: Single; format: TFloatFormat; Precision: Integer; Digits: Integer): string;
function FloatToStrF(Value: Single; format: TFloatFormat; Precision: Integer; Digits: Integer; const FormatSettings: TFormatSettings): string;
function FloatToStrF(Value: Comp; format: TFloatFormat; Precision: Integer; Digits: Integer): string;
function FloatToStrF(Value: Comp; format: TFloatFormat; Precision: Integer; Digits: Integer; const FormatSettings: TFormatSettings): string;
function FloatToStrF(Value: Currency; format: TFloatFormat; Precision: Integer; Digits: Integer): string;
function FloatToStrF(Value: Currency; format: TFloatFormat; Precision: Integer; Digits: Integer; const FormatSettings: TFormatSettings): string;
function FloatToStrF(Value: Int64; format: TFloatFormat; Precision: Integer; Digits: Integer): string;
function FloatToStrF(Value: Int64; format: TFloatFormat; Precision: Integer; Digits: Integer; const FormatSettings: TFormatSettings): string;

Converts a floating-point number to its string representation according to a chosen format mode (ffCurrency, ffExponent, ffFixed, ffGeneral, ffNumber), with Precision and Digits controlling significant digits and decimal-place count respectively; the FormatSettings variant lets the caller supply locale-specific separators instead of the global defaults.

FloatToStr

function FloatToStr(Value: Extended): string;
function FloatToStr(Value: Extended; const FormatSettings: TFormatSettings): string;
function FloatToStr(Value: Double): string;
function FloatToStr(Value: Double; const FormatSettings: TFormatSettings): string;
function FloatToStr(Value: Single): string;
function FloatToStr(Value: Single; const FormatSettings: TFormatSettings): string;
function FloatToStr(Value: Currency): string;
function FloatToStr(Value: Currency; const FormatSettings: TFormatSettings): string;
function FloatToStr(Value: Comp): string;
function FloatToStr(Value: Comp; const FormatSettings: TFormatSettings): string;
function FloatToStr(Value: Int64): string;
function FloatToStr(Value: Int64; const FormatSettings: TFormatSettings): string;

Converts a floating-point value to a string, automatically choosing the shortest of fixed or scientific notation; internally equivalent to FloatToStrF(Value, ffGeneral, 15, 0).

FloatToText

function FloatToText(Buffer: PChar; Value: Extended; format: TFloatFormat; Precision: Integer; Digits: Integer): LongInt;
function FloatToText(Buffer: PChar; Value: Extended; format: TFloatFormat; Precision: Integer; Digits: Integer; const FormatSettings: TFormatSettings): LongInt;

Converts a floating-point value to its string representation and writes the result directly into the caller-supplied Buffer (which must already have sufficient space); returns the number of characters written.

FormatFloat

function FormatFloat(const Format: string; Value: Extended): string;
function FormatFloat(const Format: string; Value: Extended; const FormatSettings: TFormatSettings): string;

Formats a floating-point value using a Delphi-style mask string (digit placeholders 0 and #, decimal point ., thousand separator ,, scientific notation E+/E-, and semicolon-separated sections for positive/negative/zero values).

GetDirs

function GetDirs(var DirName: UNICODESTRING; var Dirs: array of PUNICODECHAR): LongInt;
function GetDirs(var DirName: RAWBYTESTRING; var Dirs: array of PANSICHAR): LongInt;

Splits a path string into a null-byte-separated list of directory-name pointers, returning the number of directories found (or -1 if none); DirName must use only the OS directory separator.

IntToHex

function IntToHex(Value: LongInt; Digits: Integer): string;
function IntToHex(Value: Int64; Digits: Integer): string;
function IntToHex(Value: QWord; Digits: Integer): string;
function IntToHex(Value: Int8): string;
function IntToHex(Value: UInt8): string;
function IntToHex(Value: Int16): string;
function IntToHex(Value: UInt16): string;
function IntToHex(Value: Int32): string;
function IntToHex(Value: UInt32): string;
function IntToHex(Value: Int64): string;
function IntToHex(Value: UInt64): string;

Converts an integer to its hexadecimal string representation; with the Digits parameter the result is zero-padded to at least that many characters (never truncated if the value needs more), while the fixed-width overloads pad automatically to the type's natural hex width.

IntToStr

function IntToStr(Value: LongInt): string;
function IntToStr(Value: Int64): string;
function IntToStr(Value: QWord): string;

Converts an integer to its decimal string representation, using only as many characters as needed and prepending a minus sign for negative values.

StrToIntDef

function StrToIntDef(const S: string; Default: LongInt): LongInt;

Converts a string to an integer, returning Default instead of raising an exception if the string contains invalid characters or an invalid format.

StrToInt

function StrToInt(const s: string): LongInt;

Converts a string to an integer, accepting decimal, hexadecimal (prefix 0x/x), binary, or octal notation and enumerated-value names (case-insensitive); raises EConvertError on invalid input.

StrToFloat

function StrToFloat(const S: string): Extended;
function StrToFloat(const S: string; const FormatSettings: TFormatSettings): Extended;

Converts a string (decimal or scientific notation) to an Extended floating-point value, using the DecimalSeparator (or the supplied FormatSettings) as the decimal point; raises an exception on invalid input.

TextToFloat

function TextToFloat(Buffer: PChar; out Value: Extended): Boolean;
function TextToFloat(Buffer: PChar; out Value: Extended; const FormatSettings: TFormatSettings): Boolean;
function TextToFloat(Buffer: PChar; out Value; ValueType: TFloatValue): Boolean;
function TextToFloat(Buffer: PChar; out Value; ValueType: TFloatValue; const FormatSettings: TFormatSettings): Boolean;

Converts a null-terminated character buffer to a floating-point value using the current (or supplied) DecimalSeparator; returns True on success and False if the buffer contains an invalid character.


Other routines in SysUtils: File Name Handling Routines, File Input/Output Routines, Date/Time Routines, Conversion Routines, String Functions, Formatting Strings, PChar Related Functions.