### Author Topic: Random with Float Values?  (Read 3820 times)

#### Handoko

• Hero Member
• Posts: 2848
• My goal: build my own game engine using Lazarus
##### Re: Random with Float Values?
« Reply #15 on: February 13, 2018, 07:13:17 pm »
and how can I get values like 23,34?
I tried
Label1.Caption := floattostr (R:2:2);

#### molly

• Hero Member
• Posts: 2345
##### Re: Random with Float Values?
« Reply #16 on: February 13, 2018, 07:26:25 pm »
Ah, thanks Handoko as my glance was too quick

• Hero Member
• Posts: 7424
##### Re: Random with Float Values?
« Reply #17 on: February 13, 2018, 08:22:21 pm »
I have a super- routine for that:
Code: Pascal  [Select]
1. function dwim:dwim;
2. begin
3.  dwim :=dwim;
4. end;
Ad Brexinitum (can't help it)

• Hero Member
• Posts: 7424
##### Re: Random with Float Values?
« Reply #18 on: February 14, 2018, 09:47:46 am »
I guess the TS was looking for a very simple command like:

S := Something(R:2:2);

But so far as I know, there no such simple function in Pascal that can convert real to string and conform with the default decimal symbol.
Include sysutils, use the typehelpers.
Code: Pascal  [Select]
1.     Function ToString(const AFormat: TFloatFormat; const APrecision, ADigits: Integer): string; overload; inline;
2.     Function ToString(const AFormat: TFloatFormat; const APrecision, ADigits: Integer; const AFormatSettings: TFormatSettings): string; overload; inline;
3.     Function ToString(const AFormatSettings: TFormatSettings): string; overload; inline;
4.     Function ToString: string; overload; inline;
Easier that that set is hardly possible in any language!
« Last Edit: February 14, 2018, 09:51:17 am by Thaddy »
Ad Brexinitum (can't help it)