www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Determine decimal separator (comma vs point)

reply Andre <andre s-e-a-p.de> writes:
Hi,

I execute an external application and get some decimal numbers:

auto p = execute(["curl", "-o", "/dev/null", "-s", "-w",
		"%{time_namelookup}:%{time_appconnect}:%{time_redirect}:%{time_starttransfer}:%{time_pretransfer}:%{time_connect}:%{time_total}",
		url]);

On my windows system, the decimal separator is "," therefore I 
want
to replace the "," with "." to avoid exceptions while converting 
the value to!double.

I thought following coding should return "," on my OS because it 
is set in the region settings but "." is returned:

import core.stdc.locale;

auto lConv = localeconv();
char decSeparator = *lConv.decimal_point;

How can I determine the correct decimal separator?

Kind regards
André
Mar 07 2016
parent Andre <andre s-e-a-p.de> writes:
On Monday, 7 March 2016 at 12:29:39 UTC, Andre wrote:
 Hi,

 I execute an external application and get some decimal numbers:

 auto p = execute(["curl", "-o", "/dev/null", "-s", "-w",
 		"%{time_namelookup}:%{time_appconnect}:%{time_redirect}:%{time_starttransfer}:%{time_pretransfer}:%{time_connect}:%{time_total}",
 		url]);

 On my windows system, the decimal separator is "," therefore I 
 want
 to replace the "," with "." to avoid exceptions while 
 converting the value to!double.

 I thought following coding should return "," on my OS because 
 it is set in the region settings but "." is returned:

 import core.stdc.locale;

 auto lConv = localeconv();
 char decSeparator = *lConv.decimal_point;

 How can I determine the correct decimal separator?

 Kind regards
 André
I just found the answer: lconv* lc; setlocale(LC_NUMERIC, ""); lc = localeconv(); writeln(to!string(lc.decimal_point));
Mar 07 2016