Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dutch language problem

Posted on 1997-05-23
2
Medium Priority
?
440 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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

730 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