With System.SysUtils.TShortIntHelper
(and others) I can write:
output := 5.ToString();
to format the number 5
as string
. As well, there is System.SysUtls.TExtendedHelper
, but I'm unable to compile:
output := (5.0).ToString();
E2018: Record, object or class type required
Other versions which don't work:
5.0.ToString()
(1.0+5.1).toString()
(5+0.).toString()
(says E2029: ')' expected but ']' found)Versions which do actually work:
(1+5.1).toString()
(1.1+1+5.1).toString()
5.9e0.toString()
If the extended value is declared const
, it doesn't work either:
function TestFormat(): String;
const
q = 5.5;
begin
Result := q.ToString();
end;
But with a definition of q : extended = 5.5;
it works. So, I'm wondering why the compiler behaves this way.
You found errors in the compiler. Please report it in Quality Portal.
A workaround is to use the helpers class functions:
myString := Extended.ToString(5.5);
class function ToString(const Value: Extended): string; overload; inline; static; class function ToString(const Value: Extended; const AFormatSettings: TFormatSettings): string; overload; inline; static; class function ToString(const Value: Extended; const Format: TFloatFormat; const Precision, Digits: Integer): string; overload; inline; static; class function ToString(const Value: Extended; const Format: TFloatFormat; const Precision, Digits: Integer; const AFormatSettings: TFormatSettings): string; overload; inline; static;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With