Solved

Dutch language problem

Posted on 1997-05-23
2
438 Views
Last Modified: 2012-06-22
I have discovered that the build-in function parseFloat cannot convert floating-point numbers <well strings containing them> when using the dutch preference in your windows setup.

This is because dutch preferences show floating point numbers not with a dot <.> but with a <,>.
Is there an answer to solve this problem or do I have to write a function "<,> to <.>" all by myself.
<I'm not an expert in JavaScript yet, so any help with the function or standard solution is appreciated>.

Thanks,
Esther Barthel <the netherlands>
0
Comment
Question by:Esther052397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
RM032397 earned 100 total points
ID: 1265763
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>
0
 

Author Comment

by:Esther052397
ID: 1265764
Wow, thanks a whole lot for your answer, really great to have you work out the function for me, very much apreciated as now I will strike with the credit for it at work......as I'm just getting back into the whole programming languages, this is helping me to get a whole lot further, so again many thanks for your help.
Esther Barthel
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question