* * *

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

Handoko

  • Hero Member
  • *****
  • Posts: 2631
  • 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  :-[

Thaddy

  • Hero Member
  • *****
  • Posts: 7101
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;
inline variables like in D10.3 are a bit like Brexit: if you are given the wrong information it sounds like a good idea. Every kid loves candy, but it makes you fat and your teeth will disappear.

Thaddy

  • Hero Member
  • *****
  • Posts: 7101
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 »
inline variables like in D10.3 are a bit like Brexit: if you are given the wrong information it sounds like a good idea. Every kid loves candy, but it makes you fat and your teeth will disappear.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus