[solved] Locales decimal separator lazarus / 32-Linux ---------------------------------------------------------------------- andyH · 2022-01-06 18:36 Have an application distributed via iso, works fine. Installing from deb in a user's system generates an error when run ["100.00" is an invalid float.]. Suspect user's locale uses "," (comma) as the decimal separator, application is compiled in English, decimal separator "." (full stop). Googling for how to fix this points towards GetLocaleFormatSettings. Supposed to be in sysutils, can't find it, suspect not implemented in linux? Can someone point me in the right direction, I can parse the output of the terminal utility locale to find the user's locale, but how then do I tell my application what to use? Not yet looking to do full translations of the application, that is on the to-do list for the future. EDIT - I can do this externally, i.e. read the user's locale and set LC_NUMERIC="en_GB.UTF-8" and then reset it on close, but would prefer the application to use the existing setting for LC_NUMERIC. Would this mean changing all the code that does formatfloat(#,##0,somenumber) to an if statement if x then formatfloat(#,##0,somenumber) else formatfloat(#.##0,somenumber) ? ---------------------------------------------------------------------- Bart · 2022-01-06 20:46 FormatFloat has an overload in which you can supply a TFormatSetting. Bart ---------------------------------------------------------------------- marcov · 2022-01-06 20:48 Afaik Sysutiols.GetLocalFormatSettings() works fine, but is Windows only. ---------------------------------------------------------------------- tetrastes · 2022-01-06 22:18 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i DefaultFormatSettings.DecimalSeparator := '.';? ---------------------------------------------------------------------- Sieben · 2022-01-06 22:19 Since you seem to be on linux, try adding clocale to the uses clause of your lpr, like this for instance: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program TestEditor; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}  {$IFDEF UseCThreads}  cthreads,  {$ENDIF}  clocale,  {$ENDIF}  Interfaces, // this includes the LCL widgetset  Forms, TestMain  { you can add units after this };  //... ---------------------------------------------------------------------- andyH · 2022-01-11 18:30 Quote from: Sieben on January 06, 2022, 11:19:38 pmSince you seem to be on linux, Apologies for the delay in reponding, yes, that's why I posted in the linux sub-forum. Thanks for the info on clocale, this fixed one problem and something else learnt. The ultimate problem was a badly behaved utility (partclone) that was only partly following the locale. I'm parsing the output for a progress window. With LC_NUMERIC set so that the decimal separator is a comma, it was reporting progress correctly: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Elapsed: 00:05:00, Remaining: 00:00:01, Completed:  99,39%,   4,85GB/min,                                                    ^ correctuntil it reached 100% complete when it switched to using a full stop!! Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Elapsed: 00:05:02, Remaining: 00:00:00, Completed: 100.00%, Rate:   4,84GB/min,                                                      ^ what?Hence getting 100.00 is an invalid float in a StrToFloat. Easy to fix (try except), difficult to find ---------------------------------------------------------------------- winni · 2022-01-11 19:08 Hi! Instead of fighting against the foolish locale settings from Delphi do it yourself: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function internatStr2Float (s: string) : Double;var error,p Integer;beginp := pos (',',s);if p > 0 then s[p] := '.';val (s,result,error);// do something if error <> 0end;   Winni