Solved

How to change comma to point in number formating?

Posted on 2002-06-15
6
563 Views
Last Modified: 2008-01-16
The problem is, in English, numbers are like this:

10,000,000.00

in Portuguese:

10.000.000,00

So, how can I change the locale/regional settings so that I can use a period for grouping digits and a comma for the decimal places? Some people here have IE in English and some use IE in Portuguese, so how do I force the setting for my javascript code despite of the client computer setting?
0
Comment
Question by:acerola
6 Comments
 
LVL 1

Expert Comment

by:handful
ID: 7081122
HI dude( I am brazilian too but in this forum I post in english )

Well, the point is : Javascript's interpreter is based on the foreing aspect of the numbers..so...
the only thing you can do to pass over  it..
is to make a function that works around it only at 'delivery' time ( you cannot do operations with this format because the number will be a string.
( there is no number format like the one we usehere in brazil )

Like this :

function commaToPoints(str){
 strRegExPoint=/\./g
 strRegExComma=/\,/g
 str.replace(strRegExPoint,'#')
 str.replace(strRegExComma,'.')
 str.replace(/#/,',')
}

That is only a idea.. not tested.

0
 
LVL 1

Author Comment

by:acerola
ID: 7081140
That is pretty much what I am using right now. I made two functions. One that takes a floating point number and convert to a string in the form 1.234.567,89 and another which does the opposite. Take a look:

=======================================================

function num2bra(valor) {

  var str,str1,str2;

  str = String(Math.round(valor*100)/100);
 
  str = str.replace(/\./,",");

  str1 = String(str.match(/\d+/));
 
  if (str1 == "null")
    str1 = "0";

  str2 = "";

  for(count=str1.length-3; count >= -2; count -= 3)
    str2 = str1.substring(count,count+3) + "." + str2;

  str2 = str2.substring(0,str2.length-1);

  str1 = String(str.match(/\,\d+/));

  if (str1.length == 4)
    str2 = str2 + ",00"
  else if (str1.length == 2)
    str2 = str2 + str1 + "0"
  else if (str1.length == 3)
    str2 = str2 + str1

  return str2;

}

=======================================================

function bra2num(texto) {

  var strA;
 
  strA = String(texto);
 
  strA = String(strA.replace(/\./g,""));

  strA = String(strA.replace(/\,/g,"."));
 
  return parseFloat(strA);

}
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7081872
You can either retrieve the current language being used (retrieve using:)
naigator.systemLanguage

Or you can create two seperate textboxes one for the integer numbers and the other for the floating point numbers.

Lasyt thing is that most sites that "we" create are for our own country. English users are then disposed off since we also use the , instead of the ..

CJ
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:acerola
ID: 7082707
It's no use for me knowing the system language. Here in Brazil it is a mess. Some people use Brazilian windows/ie. Some use American windows/ie. Some use American window/ie set to Brazililan regional settings, and vice-versa. But all of them need to use the brasilian standart for numbers.

A even bigger mess is my web hosting. IIS is set to brazilian standarts, but mysql server is in english. So when sending/recieving sql queries I must also do the conversion.

I need to change the browser's javascript interpretation of numbers, so that it recognizes 0,50 as a fraction and not the number 50.
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8285386
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8360673
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now