Recent

Author Topic: StrtoFloat managing  (Read 15223 times)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: StrtoFloat managing
« Reply #30 on: May 19, 2018, 09:01:15 pm »
Sorry to retake this old topic.

Finally im creating the final make up and im back with this issue.
I can manage all with a smple solution: converting info like this "300.21" (string) to this "300,21" (string)

Any simple function?
that is a decimal separator here try this one
Code: Pascal  [Select][+][-]
  1. var
  2.   vFormat : TFormatSettings;
  3. begin
  4.   vFormat := DefaultFormatSettings;
  5.   vFormat.DecimalSeparator := '.'; //or what ever your data require.
  6.   Result := StrToFloat(aValue, vFormat);
  7. end;
  8.  
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: StrtoFloat managing
« Reply #31 on: May 21, 2018, 07:34:42 am »
Any simple function?

Using Taazz's method:
Code: Pascal  [Select][+][-]
  1. uses
  2.   sysutils;
  3.  
  4. function SimpleSolution(inStr: String): String;
  5. var
  6.   Fmt: TFormatSettings;
  7.   dbl: double;
  8. begin
  9.   Fmt := DefaultFormatSettings;
  10.   Fmt.DecimalSeparator:='.';
  11.   dbl := StrToFloat(inStr, Fmt);
  12.  
  13.   Fmt := DefaultFormatSettings;
  14.   Fmt.DecimalSeparator:=',';
  15.   Fmt.ThousandSeparator:='.';
  16.   Result := FloatToStrF(dbl, ffNumber, 0, 2, Fmt);
  17. end;

 

TinyPortal © 2005-2018