I have a code which has a variable of Single datatype , but i want to display is in a message box. For example
VAR data:Single;
data:=0;
data:=5633.67+1290.965;
Msgbox('The sum of Fractional number is-:'+IntTostr(data),mbinformation,MB_OK);
There are at least two options I can think of right now. The first one is FloatToStr function, which is undocumented, or the official way of using Format function, which gives you much better flexibility in specifying format that you want. Here is an example of FloatToStr function:
var
S: string;
Value: Single;
begin
Value := 1.2345;
S := FloatToStr(Value);
MsgBox('Value is: ' + S, mbInformation, MB_OK);
end;
And here is an example that uses Format function. There is shown how to display a floating value in the General format and how to show the same value with 2 decimal places by using Fixed format. For more information about formats refer to the Delphi help for the Format function:
var
S: string;
Value: Single;
begin
Value := 1.2345;
S := Format('Value is: %g', [Value]);
MsgBox(S, mbInformation, MB_OK);
S := Format('Value is: %.2f', [Value]);
MsgBox(S, mbInformation, MB_OK);
end;
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