Antje Hofmann: Kommazahlen in Javascript und Bildschirmausgabe

Beitrag lesen

Hallo Benne

Einige Browser kennen die wunderschöne Funktion toLocaleString().
Der Aufruf 2.3.toLocaleString()
toLocalString ist allerdings für Datumsobjekte gedacht und es dürfte nicht wundern, wenn die Verwendung keine vernünftigen Ergebnisse für diesen Fall liefert.

nein, lediglich für das Date-Objekt ist das eine allgemein bekannte Methode.

Die ECMA-262 Spezifikation sagt zu dieser Methode:

Object.prototype.toLocaleString ( )

This function returns the result of calling toString().

NOTE 1
This function is provided to give all Objects a generic toLocaleString interface, even though not all may use it. Currently, Array, Number, and Date provide their own locale-sensitive toLocaleString methods.

und direkt zum Number-Objekt:

Number.prototype.toLocaleString()

Produces a string value that represents the value of the Number formatted according to the conventions of the host environments current locale. This function is implementation-dependent, and
it is permissible, but not encouraged, for it to return the same thing as toString.

Ich finde die Umsetzung im IE das tatsächlich übliche Format (im Deutschen eben der Tausenderpunkt und das Komma als Dezimalzeichen)
auszugeben sehr sinnvoll.

Viele Grüße

Antje