Recent

Author Topic: decimal separator  (Read 2020 times)

franzala

  • New Member
  • *
  • Posts: 39
decimal separator
« on: May 23, 2022, 06:53:24 pm »
With Lazarus 2.0.10 under Ubuntu 20.04 and french as language
(/etc/default/locale file shows      LANG="fr_FR.UTF-8")
I obtain a dot as decimal separator with the numerical keypad.
How could I change it to a comma, which I obtain with other softwares as Libre Office Spreadsheets for instance.

AlexTP

  • Hero Member
  • *****
  • Posts: 2382
    • UVviewsoft
Re: decimal separator
« Reply #1 on: May 23, 2022, 07:05:08 pm »

Handoko

  • Hero Member
  • *****
  • Posts: 5129
  • My goal: build my own game engine using Lazarus
Re: decimal separator
« Reply #2 on: May 23, 2022, 07:06:21 pm »
Drop a TEdit on the form and put this code on the TEdit's OnChange event:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Edit1Change(Sender: TObject);
  2. var
  3.   D: Double;
  4. begin
  5.   DecimalSeparator := ',';
  6.   if not(TryStrToFloat(Edit1.Text, D)) then
  7.     Caption := '(error)'
  8.   else
  9.     Caption := D.ToString;
  10. end;

Read more:
https://www.freepascal.org/docs-html/rtl/sysutils/strtofloat.html
https://wiki.lazarus.freepascal.org/DecimalSeparator
https://www.freepascal.org/docs-html/rtl/sysutils/tformatsettings.html
« Last Edit: May 23, 2022, 07:08:45 pm by Handoko »

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: decimal separator
« Reply #3 on: May 23, 2022, 07:15:19 pm »
Assign to FormatSettings.DecimalSeparator ?
https://stackoverflow.com/questions/25109497/decimalseparator-in-sysutils-and-system-sysutils
No, make a copy of FormatSettings (an instance of a record) as a local instance of TFormatSettings (A record declaration) and change it there.
Specialize a type, not a var.

Sieben

  • Sr. Member
  • ****
  • Posts: 310
Re: decimal separator
« Reply #4 on: May 23, 2022, 07:58:31 pm »
Try adding unit cLocale to the uses clause of your .lpr file, after(!) cThreads:

Code: Pascal  [Select][+][-]
  1. program MyProg;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}
  7.   cThreads,
  8.   cLocale,
  9.   {$ENDIF}
  10.   Interfaces, Forms, //...
  11.  
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: decimal separator
« Reply #5 on: May 23, 2022, 08:43:06 pm »
That's pretty strange. Locales should be properly loaded on linux without including cLocale or setting Decimal/Thousand separator IMO.
You should check what locale is loaded with echo $LANG or echo $LC_NUMERIC. Maybe your locale isn't properly installed.

 

TinyPortal © 2005-2018