Foreign langauge arrray element separator

A

Andrew Poulos

When I create an array I use commas as the separator between elements of
the array e.g [1.1, 2.2, 3.3] but what happens with languages that use
commas as a number's "decimal point"? e.g. [1,1, 2,2 , 3,3] is now a 6
element array.

Andrew Poulos
 
R

Richard Cornford

Andrew said:
When I create an array I use commas as the separator between elements of
the array e.g [1.1, 2.2, 3.3] but what happens with languages that use
commas as a number's "decimal point"? e.g. [1,1, 2,2 , 3,3] is now a 6
element array.

That is irrelevant. Javascript numeric literals only use the '.'
character as a decimal point.

Richard.
 
A

Andrew Poulos

Richard said:
Andrew said:
When I create an array I use commas as the separator between elements of
the array e.g [1.1, 2.2, 3.3] but what happens with languages that use
commas as a number's "decimal point"? e.g. [1,1, 2,2 , 3,3] is now a 6
element array.

That is irrelevant. Javascript numeric literals only use the '.'
character as a decimal point.

But what happens when someone, from a place where it's normal to use
commas, enters a number with a comma into a field from which I use
javascript to get the value? Do I have to do a conversion like this on it:

num = num ^ "";
num = parseFloat( num.replace(/,/g, ".") );

Andrew Poulos
 
B

Bogdan Blaszczak

Andrew Poulos:
commas as a number's "decimal point"? e.g. [1,1, 2,2 , 3,3] is now a 6
element array.
But what happens when someone, from a place where it's normal to use
commas, enters a number with a comma into a field from which I use

input value is a string
your array presents something like this
['1,1', '2,2' , '3,3']
and array doesn't "destroy"
javascript to get the value? Do I have to do a conversion like this on it:

if you want to use them in mathematical operation...

num = num ^ "";
num = parseFloat( num.replace(/,/g, ".") );

so, imagine someone enters "price number format"?
1,234,567.00
what are you going to do?
 
V

VK

Andrew said:
But what happens when someone, from a place where it's normal to use
commas, enters a number with a comma into a field from which I use
javascript to get the value? Do I have to do a conversion like this on it:

num = num ^ "";
num = parseFloat( num.replace(/,/g, ".") );

Something like that. But first you have to spell clearly on the page in
what format do you want to have the number typed. There is nothing
"illegal" to spell your formatting rules. Comma is used as "readability
separator" in the US and as decimal point in some Western countries.
Period used as decimal point in the US and as "readability separator"
in Japan, where period is used as decimal point. Unless you know
exactly that format is used by the customer, any attempt to guess the
entered number is pretty futil. Even if you manage to know the
SystemLanguage, it doesn't prove anything in application to this
particular customer sitting and typing on the computer. So just play
from your side of the table: "please inter the numbers in this format:
XXXXX and I don't give a damn what you've been thaught in your damn
local school" :) Obviously the required format should be as used by
the majority of the expected customers. If you cannot determine such
majority, then drop a coin.
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top