如何在 Octave 中获取环境小数点分隔符

How to get the environment decimal separator in Octave

我需要在 Octave 中为变量分配环境小数点分隔符。

比如pc设置成US格式

>> decsep
ans = .

相反,如果您 运行 来自具有欧洲十进制格式的 PC 的脚本,则输出将是

>> decsep
ans = ,

在 Linux 上,您可以使用:

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

您可以使用Java获取小数点分隔符:

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

或者,您可以使用以下 PowerShell(powershell.exe 或 pwsh.exe)脚本:

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