How to get the environment decimal separator in Octave

Viewed 571

I need to assign to a variable the environment decimal separator in Octave.

For example, if the pc is set in US format

>> decsep
ans = .

Instead if you run the script from a pc that has European decimal format the output will be

>> decsep
ans = ,
2 Answers

On Linux, you can use:

[~, s] =  system('locale decimal_point'); %returns decimal separator and a '↵'
decsp = s(1); %Required answer   

You can use Java to get the decimal separator:

Format  = javaMethod( "getInstance", "java.text.DecimalFormat" );
Symbols = javaMethod( "getDecimalFormatSymbols", Format );
Sep     = javaMethod( "getDecimalSeparator", Symbols )

Alternatively you can use the following PowerShell (powershell.exe or pwsh.exe) script:

[~, s] = system("pwsh -command (Get-Culture).NumberFormat.NumberDecimalSeparator");
Sep = s(1);
Related