Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why differs German and Swiss Number to String Conversion?

I'm just trying to convert a float I read from Exel to a string with using a comma as decimal separator and two digits behind the comma. I try the following code

$a = 707.63790474
$l = New-Object System.Globalization.CultureInfo("de-CH")
"CH: " + $a.ToString("F2", $l)


$l = New-Object System.Globalization.CultureInfo("de-DE")
"DE: " + $a.ToString("F2", $l)

$l = New-Object System.Globalization.CultureInfo("en-US")
"US: " + $a.ToString("F2", $l)

and get

CH: 707.64
DE: 707,64
US: 707.64

But to my knowledge a comma is used as decimal separator in Switzerland, unless it is a currency cf. http://en.wikipedia.org/wiki/Decimal_mark. Do I miss something?

like image 226
bernd_k Avatar asked Nov 14 '11 15:11

bernd_k


2 Answers

Type (New-Object System.Globalization.CultureInfo("de-CH")).numberFormat to get numberformatinfo for de-CH

You'll get:

CurrencyDecimalDigits    : 2
CurrencyDecimalSeparator : .
IsReadOnly               : False
CurrencyGroupSizes       : {3}
NumberGroupSizes         : {3}
PercentGroupSizes        : {3}
CurrencyGroupSeparator   : '
CurrencySymbol           : Fr.
NaNSymbol                : n. def.
CurrencyNegativePattern  : 2
NumberNegativePattern    : 1
PercentPositivePattern   : 1
PercentNegativePattern   : 1
NegativeInfinitySymbol   : -unendlich
NegativeSign             : -
NumberDecimalDigits      : 2
NumberDecimalSeparator   : .
NumberGroupSeparator     : '
CurrencyPositivePattern  : 2
PositiveInfinitySymbol   : +unendlich
PositiveSign             : +
PercentDecimalDigits     : 2
PercentDecimalSeparator  : .
PercentGroupSeparator    : '
PercentSymbol            : %
PerMilleSymbol           : ‰
NativeDigits             : {0, 1, 2, 3...}
DigitSubstitution        : None

As you can see both NumberDecimalSeparator and CurrencyDecimalSeparator are .

like image 95
jon Z Avatar answered Nov 06 '22 14:11

jon Z


No, it looks like Switzerland uses . as the decimal separator (like normal people do), so this is correct output:

http://publib.boulder.ibm.com/infocenter/forms/v3r5m1/index.jsp?topic=%2Fcom.ibm.form.designer.locales.doc%2Fi_xfdl_r_formats_de_CH.html

like image 21
MusiGenesis Avatar answered Nov 06 '22 14:11

MusiGenesis