Christian Kruse: localeCompare und negative Zahlen

Beitrag lesen

problematische Seite

Hallo JürgenB,

danke. Ich werde dann wohl localeCompare nur für Nicht-Zahlen nehmen, und für Zahlen die alte Funktion behalten müssen. Schade.

Ich hab jetzt mal im Standard geblättert… auf den ersten Blick sieht das nach „unterspezifiziert“ aus. Der sagt zum eigentlichen Vergleich nämlich gar nichts aus. Der sagt nur das hier:

The two Strings are compared in an implementation-defined fashion.

Und:

The result is intended to order String values in the sort order specified by the effective locale and collation options computed during construction of collator, and will be negative, zero, or positive, depending on whether x comes before y in the sort order, the Strings are equal under the sort order, or x comes after y in the sort order, respectively.

Und:

[[Numeric]] is a Boolean value, specifying whether numeric sorting is used.

Kein Wort darüber, wie eigentlich genau verglichen werden soll. Ich könnte mir sogar vorstellen, dass das abhängig von OS und Umgebung/Locale ist…

LG,
CK