Have you checked the Console log output ? Your code produces errors on all 4 lines. Two things are wrong:
- JavaScript does not recognize 123,45 and 9,22 as valid numbers.
- You have to use
var
, not Var
. JavaScript is case sensitive.
Now how to get JS to accept the German decimal format ? I don't think it is possible. While there is a function
toLocaleString()
which can create localized output, there doesn't seem to be a function
fromLocaleString()
to accept localized input (123,34) and turn it into a JS decimal value. So in your code, I think you
have to use the decimal point. Then if you want German output, you can do this:
JavaScript:
var a=123.45;
var b=9.22;
var c=a+b;
alert(c.toLocaleString("de-DE"));
which will output 132,67