Hello from England, Esther!

I find your question very interesting.

No you don't have to write the function yourself, because I have done it for you - well it's a start anyway.

I assume that numberstring is input into an INPUT type="text"

I have first assumed input of "1234,56"

The first function will convert that to a floating number by the following method:

Determine position of ","

Extract string before "," A

Extract string aafter "," B

return parseFloat of A + "." + B

But this ignores the possiblity of the input string having a "." and not a ",", or being a whole number (integer) with no decimal places. So the second function, slightly more complicated, deals with that.

Yes, you can write much more complex functions to check that input is numeric, but such functions are standard in most books.

<HTML><HEAD>

<TITLE>Dutch Floating Point</TITLE>

<SCRIPT LANGUAGE="JavaScript">

<!--

// "Dutch Floating Point" is comma "," and not point "."

function parseNfloat1(S) {

// returns floating point number from numberstring S written with "," for decimal.

// but will return NaN (Not A NUMBER) for any numberstring S written with "." for decimal!

// and also returns NaN for integer-strings like "1234"

var L = S.length

var P = S.indexOf(",")

return( parseFloat(S.substring(0,P)+"."+S.substring(P+1,L)) )

}

function parseNfloat(S) {

// returns floating point number from numberstring S written with "," for decimal.

// but will also return correct value for any numberstring S written with "." for decimal

// and will return correct value for integer strings too

var L = S.length

var P = S.indexOf(",")

if (P==-1) return parseFloat(S);

else return( parseFloat(S.substring(0,P)+"."+S.substring(P+1,L)) )

}

//--end-->

</SCRIPT>

</HEAD>

<BODY>

<SCRIPT LANGUAGE="JavaScript">

<!--

// alert(parseNfloat1("1234,56"))

// alert(parseNfloat1("1234.56"))

alert(parseNfloat("1234,56"))

alert(parseNfloat("1234.56"))

alert(parseNfloat("-1234,56"))

alert(parseNfloat("-1234.56"))

alert(parseNfloat("1234"))

//--end-->

</SCRIPT>

</BODY></HTML>

I find your question very interesting.

No you don't have to write the function yourself, because I have done it for you - well it's a start anyway.

I assume that numberstring is input into an INPUT type="text"

I have first assumed input of "1234,56"

The first function will convert that to a floating number by the following method:

Determine position of ","

Extract string before "," A

Extract string aafter "," B

return parseFloat of A + "." + B

But this ignores the possiblity of the input string having a "." and not a ",", or being a whole number (integer) with no decimal places. So the second function, slightly more complicated, deals with that.

Yes, you can write much more complex functions to check that input is numeric, but such functions are standard in most books.

<HTML><HEAD>

<TITLE>Dutch Floating Point</TITLE>

<SCRIPT LANGUAGE="JavaScript">

<!--

// "Dutch Floating Point" is comma "," and not point "."

function parseNfloat1(S) {

// returns floating point number from numberstring S written with "," for decimal.

// but will return NaN (Not A NUMBER) for any numberstring S written with "." for decimal!

// and also returns NaN for integer-strings like "1234"

var L = S.length

var P = S.indexOf(",")

return( parseFloat(S.substring(0,P

}

function parseNfloat(S) {

// returns floating point number from numberstring S written with "," for decimal.

// but will also return correct value for any numberstring S written with "." for decimal

// and will return correct value for integer strings too

var L = S.length

var P = S.indexOf(",")

if (P==-1) return parseFloat(S);

else return( parseFloat(S.substring(0,P

}

//--end-->

</SCRIPT>

</HEAD>

<BODY>

<SCRIPT LANGUAGE="JavaScript">

<!--

// alert(parseNfloat1("1234,5

// alert(parseNfloat1("1234.5

alert(parseNfloat("1234,56

alert(parseNfloat("1234.56

alert(parseNfloat("-1234,5

alert(parseNfloat("-1234.5

alert(parseNfloat("1234"))

//--end-->

</SCRIPT>

</BODY></HTML>