[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to change comma to point in number formating?

Posted on 2002-06-15
6
Medium Priority
?
570 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
[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
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
Technology Partners: 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!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

649 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