Forum > Windows

Calculation problem

(1/2) > >>

o002str:
Hello, my name is Huib van Straaten and I am 72 years old.
To keep my brain fit, I started teaching myself programming in Lazarus/FreePascal.
Because I only have a good command of Dutch, I use Google translate to translate my question into English.
My challenge is to write a tax program, in which I want to be able to calculate in advance what the best options are to pay as little tax as possible, or to receive as much tax back as possible.
Now my problem. Depending on whether I use my desktop (with Linux as OS) or my laptop (Windows 11), I run into the following problem when testing the program.
When I test a calculation under Linux, I have to change a decimal comma (as is usual here in the Netherlands) to a point (as is usual in the USA).
When I test the same calculation under Windows, I have to change the decimal point to a comma.
My question now is, is it possible to consult the operating system with the help of a function (which I cannot find) which notation (point or comma) is used to perform a calculation with decimals?
Then I can write a function myself, with which I no longer have to worry about which operating system my program is running under.
After 1.5 months of searching the internet, I have given up the courage to search further and I ask for help with this.

Thank you in advance for a response.
Kind regards,
Huib

Sieben:
There is a global var in FPC/Lazarus called DefaultFormatSettings which, aside from other settings for formatting date or time display etc, also holds information about the DecimalSeparator.

From your description I guess that your program does not adopt to the system settings on Linux, as they should be the same on both Windows and Linux, presuming both are configured to dutch standard. You can change this by adding the unit cLocale to the uses clause of eg your main form or *.lpr file. Having done this your code should work the same on both systems.

Bart:
A better option might be to use the conversion routines (string to number conversion) that accept a TFormatSettings parameter.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  SysUtils;var  S: String;  FS: TFormatSettings;  D: Double;begin  FS.DecimalSeparator := ',';  //when in the Netherlands, go Dutch  S := '1,25';  D := StrToFloat('1,23', FS);end.
Notice that when you set DefaultFotmatSettings.DecimalSeparator := ',' you may be in for a surprise on Windows.
Art some poit Windows may send a message that system wide settings for some formatsetting hase been changed (or may have been changed), and at that point your DefaultFormatSetting.DecimalSpearator will be reset to what Windows decides it should be.

(In a Lazarus GUI application, you can disable this Windows feature using Application.UpdateFormatSettings := False;  )

B.t.w. The NL Delphi Forum also has a section for Lazarus/Freepascal. And general programming questions about Pascal can be asked there too (in Dutch).

Bart

Sieben:
The point I was trying to make is that in order to 'go Dutch' on a dutch Linux, you just need to include cLocale. I'd suggest doing it in the *.lpr file like this for example:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program MyProg; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}  cThreads,  cLocale,  {$ENDIF}  Interfaces, Forms, // etc... 

o002str:
Translated by Google Translate
Dear Sieben and Bart,

Thanks for your quick response and I'll try your suggestions tonight.
I will let you know the result as soon as possible.
It may sound strange, but I have set openSuze (just like Windows) as Dutch. Still, I have to count on a point there.

Huib

Navigation

[0] Message Index

[#] Next page

Go to full version