weabow 6 Posted August 5, 2021 I have this piece of code : showmessage(formatfloat('###,###.00', 1234.25)); It runs fine under Windows, and if I change the decimal separator in the OS, it's taken into account. On Mac, I always have the , (I'm french), even if I change it in the parameters of the OS. An idea ? Share this post Link to post
Fr0sT.Brutal 900 Posted August 5, 2021 What happens if you explicitly create new TFormatSettings with current locale and call the function with resulting record? Share this post Link to post
weabow 6 Posted August 5, 2021 Well, I'm not familiar with this. I thougth that formatfloat took OS settings into account automatically. Do you mean I have something else to do ? Share this post Link to post
mausmb 13 Posted August 5, 2021 Hi, Use System.SysUtils.FormatSettings.DecimalSeparator one example if FormatSettings.DecimalSeparator = ',' then LText := StringReplace(LText, '.', FormatSettings.DecimalSeparator, [rfReplaceAll]) else LText := StringReplace(LText, ',', FormatSettings.DecimalSeparator, [rfReplaceAll]); br, m Share this post Link to post
weabow 6 Posted August 5, 2021 Looks fine. But me need is to be synchronized with the plateform settings, maybee France, USA or UK. Sometimes it's a , and in other cases it's a . How can I know which it is on the OS ? Share this post Link to post
Lajos Juhász 293 Posted August 5, 2021 13 minutes ago, weabow said: How can I know which it is on the OS ? The default should be populated with the values that are supplied by the OS - http://docwiki.embarcadero.com/Libraries/Sydney/en/System.SysUtils.TFormatSettings.Create Share this post Link to post
mausmb 13 Posted August 5, 2021 36 minutes ago, mausmb said: if FormatSettings.DecimalSeparator = ',' then LText := StringReplace(LText, '.', FormatSettings.DecimalSeparator, [rfReplaceAll]) else LText := StringReplace(LText, ',', FormatSettings.DecimalSeparator, [rfReplaceAll]); This solves all scenarios and local settings Share this post Link to post
Fr0sT.Brutal 900 Posted August 5, 2021 2 hours ago, mausmb said: Use System.SysUtils.FormatSettings.DecimalSeparator BAD advice. Really bad. Global variables are evil. Moreover, this variable won't update on change either. 4 hours ago, weabow said: Well, I'm not familiar with this. I thougth that formatfloat took OS settings into account automatically. Do you mean I have something else to do ? In VCL changes are auto-applied by TForm's internal message handler. FMX doesn't track system changes even on Windows (checked with 10.3). So it's up to you to refresh them. I'd advice you to use your own instance of FmtSett received by TFormatSettings.Create(SysLocale.DefaultLCID) with all Format functions and refresh them periodically or when they're used. Probably there's more clever option but I'm not aware of any. Share this post Link to post
weabow 6 Posted August 5, 2021 Thanks. I put TFormatSettings.Create(SysLocale.DefaultLCID); but the ide doesn't want it. Looking inside help...doesn't help ! Share this post Link to post
weabow 6 Posted August 5, 2021 I make it run : fs := TFormatSettings.Create(SysLocale.DefaultLCID); //fs.DecimalSeparator := '.'; System.SysUtils.FormatSettings := fs; Now it compiles, but no change under MacOs. If I set hardly decimalpoint it runs fine. But my need is to detect the OS parameter. I think there's a bug. Share this post Link to post
David Heffernan 2345 Posted August 5, 2021 2 hours ago, weabow said: But my need is to detect the OS parameter. I think there's a bug. Looks like it. Submit a bug report. Share this post Link to post
Remy Lebeau 1396 Posted August 5, 2021 2 hours ago, weabow said: I make it run : fs := TFormatSettings.Create(SysLocale.DefaultLCID); //fs.DecimalSeparator := '.'; System.SysUtils.FormatSettings := fs; That is wrong. Don't assign the new TFormatSettings instance to the global FormatSettings variable at all (in fact, pretend that global variable doesn't even exist). Pass the new TFormatSettings instance directly to FormatFloat() instead, eg: fs := TFormatSettings.Create(SysLocale.DefaultLCID); // customize fs as needed... ShowMessage(FormatFloat('###,###.00', 1234.25, fs)); 1 Share this post Link to post
Fr0sT.Brutal 900 Posted August 6, 2021 18 hours ago, Fr0sT.Brutal said: use your own instance of FmtSett received by TFormatSettings.Create(SysLocale.DefaultLCID) with all Format functions and refresh them periodically or when they're used Repeat Share this post Link to post
Rollo62 536 Posted August 6, 2021 (edited) Stupid question, is it possible that Win and Macos have different format setting ? Should be standard in both, but maybe isnt. Edited August 6, 2021 by Rollo62 Share this post Link to post
David Heffernan 2345 Posted August 6, 2021 52 minutes ago, Rollo62 said: Stupid question, is it possible that Win and Macos have different format setting ? Should be standard in both, but maybe isnt. It depends on the locale rather than the os Share this post Link to post
Dave Nottage 557 Posted August 6, 2021 (edited) 5 hours ago, Rollo62 said: Stupid question, is it possible that Win and Macos have different format setting ? Well, they're obtained differently, since they're different operating systems. The problem here is either in the call to CFLocaleCopyCurrent or CFLocalGetValue, which is what Delphi currently uses to obtain the decimal separator. The decimalSeparator method of NSLocale gives the correct result. Edited August 6, 2021 by Dave Nottage 1 Share this post Link to post