will this always return the current system decimal separator? (SOLVED)
02-05-2018, 08:32 AM (This post was last modified: 02-05-2018 11:23 PM by StephenG1CMZ.)
Post: #1
 StephenG1CMZ Senior Member Posts: 845 Joined: May 2015
will this always return the current system decimal separator? (SOLVED)
I am not aware of a built-in "get the current decimal separator" function and I needed one because I have a program in which the system calls usually deliver "0." but ocassionally return "0".

So, I needed to find out whether to add a "." or a ",".

This seems to work - but could there be a "fix 0" mode which might hide the separator?
Code:
  EXPORT DecSepNow()  //RETURN current system decimal separator  BEGIN   LOCAL ST:=STRING(π);//ANY REAL   LOCAL DOT:=INSTRING(ST,".");   LOCAL COM:=INSTRING(ST,",");     RETURN MID(ST,MAX(DOT,COM),1);  END;
Or is there a better way?

Stephen Lewkowicz (G1CMZ)... USA's changing goals
In 1960s, delivering a man to the Moon...
In 2020s, delivering a vote to the electors.
02-05-2018, 09:54 AM (This post was last modified: 02-05-2018 10:21 AM by Didier Lachieze.)
Post: #2
 Didier Lachieze Senior Member Posts: 1,221 Joined: Dec 2013
RE: will this always return the current system decimal separator?
(02-05-2018 08:32 AM)StephenG1CMZ Wrote:  This seems to work - but could there be a "fix 0" mode which might hide the separator?

It doesn't work in FIX 0 as in this number format mode STRING(π) returns "3".

Instead, you can use the Home Settings variable HSeparator, this should work whatever the number format:

Code:
EXPORT DecSepNow() //RETURN current system decimal separator BEGIN   RETURN IFTE((HSeparator MOD 9)<4,".",","); END;

Another way of doing it based on your program would be to force the number of digits after the decimal separator:

Code:
EXPORT DecSepNow() //RETURN current system decimal separator BEGIN  LOCAL ST,ND:=HDigits;  HDigits:=1;     //Set number of digits after the decimal separator to 1  ST:=STRING(π);  //Set ST to "3.1" or "3,1"  HDigits:=ND;    //Restore number of digits after the decimal separator  RETURN ST(2,1); //Return second character of ST END;
02-05-2018, 10:35 AM
Post: #3
 StephenG1CMZ Senior Member Posts: 845 Joined: May 2015
RE: will this always return the current system decimal separator?
Of the two, I much prefer your version reading Hseparator. Thank you.
I try to avoid solutions that change modes and then restore them - unless there is no other way - as there is always the risk that the user will interrupt a program at just the wrong time - and then wonder what has changed the settings.

Stephen Lewkowicz (G1CMZ)... USA's changing goals
In 1960s, delivering a man to the Moon...
In 2020s, delivering a vote to the electors.
02-06-2018, 02:27 AM
Post: #4
 toml_12953 Senior Member Posts: 1,468 Joined: Dec 2013
RE: will this always return the current system decimal separator? (SOLVED)
(02-05-2018 10:35 AM)StephenG1CMZ Wrote:  Of the two, I much prefer your version reading Hseparator. Thank you.
I try to avoid solutions that change modes and then restore them - unless there is no other way - as there is always the risk that the user will interrupt a program at just the wrong time - and then wonder what has changed the settings.

Even worse are programs that change modes and don't restore them!

Tom L
If you buy a drink for someone in order to congratulate them,
is it a Mazel Tov cocktail?
02-06-2018, 04:21 AM
Post: #5
 Carlos295pz Senior Member Posts: 363 Joined: Sep 2015
RE: will this always return the current system decimal separator? (SOLVED)
Oh! this is something useful to identify when using EXPR()

Viga C | TD | FB
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)