-
Numbers with "," and "."
Hi:
Does someone knows how can i put a , or a . between numbers so i can display an amount of money, but i can still use them as values so i can add them.
Thanks
Mariana
-
dollars = 10;
cents = 56;
dollars +=10;
money_display = "$"+dollars+"."+cents;
trace(money_display);
-
thanks but my question is more like how can i convert and input like 20000 to 20,000.
Thanks
-
Originally posted by oldnewbie
dollars +=10;
dollars *=10;
-
I suppose that if I answer that... It's then going to be...
But how can I format 1,000,000,000.00...
Ask George, he's about to spend more than that!
Last edited by oldnewbie; 02-28-2003 at 12:42 PM.
-
sorry... let me fix that.
-
-
thanks a lot i have it.
on (press){
var _array2 = new Array();
var _array = texto.split("");
_array.reverse();
for (var i = 0; i < _array.length; i++) {
_array2.push(_array[i]);
if (!((i + 1) % 3) && _array.length > 3) {
_array2.push(",");
}
}
texto2 = _array2.reverse().join("");
}
-
-
Code:
TextField.prototype.toNumber = function(decimal) {
var _array = this.text.split("");
var _array2 = new Array();
var _array3 = ["."];
for (var ii = 0; ii < decimal; ii++) {
_array3.push(_array.pop());
}
_array.reverse();
for (var i = 0; i < _array.length; i++) {
_array2.push(_array[i]);
if (!((i + 1) % 3) && _array.length > 3 && _array.length - 1 != i) {
_array2.push(",");
}
}
this.text = _array2.reverse().concat(_array3).join("");
};
_txt.toNumber(2);
-
oh... I could have done that, you said you wanted decimals too
-
-
Originally posted by oldnewbie
Send both to George!
In the mail...
-
Hi:
Yes i preferably nead decimals but your code has a but 'cause if i input for example 5000.423423 i will get 50,00.,423,423.
Thanks
-
There has to be an easier way. I had a play with gSolo's stuff to get decimal formatting. This works, but it looks a bit Kludgey to me.
PHP Code:
function format_number(num, decimalplaces) {
var before_the_point;
var after_the_point;
var _array;
var _output;
after_the_point = num.toString().split(".")[1];
switch (decimalplaces) {
case 0 :
num = Math.round(num);
after_the_point = "";
case undefined :
break;
default :
after_the_point = Number("0."+after_the_point);
after_the_point *= Math.pow(10, decimalplaces);
after_the_point = Math.round(after_the_point).toString();
}
before_the_point = num.toString().split(".")[0];
_array = return_comma_separated_array(before_the_point.split(""));
_output += _array.reverse().join("");
if( after_the_point.length ) {
_array = return_comma_separated_array(after_the_point.split("").reverse());
_output += "."+_array.join("");
}
return _output;
}
function return_comma_separated_array(_array) {
// Array size will change during the loop
var _itmax = _array.length;
var _array2 = new Array();
for (var i = 0; i<_itmax; i++) {
if (!(i%3) && i>0) {
_array2.push(",");
}
_array2.push(_array.pop());
}
return _array2;
}
trace(format_number(123456789.298, 0));
trace(format_number(369.98, 0));
trace(format_number(2468.123456));
trace(format_number(123456789.2, 0));
-
solution
on (press){
var _array = texto.split(".");
var _array2 = _array [0];
var texto2 = _array2
var _array3= texto2.split ("");
_array3.reverse();
var _array4= new Array ();
var _array5 = ["."];
for (var i = 0; i < _array3.length; i++) {
_array4.push(_array3[i]);
if (!((i + 1) % 3) && _array3.length > 3 && _array3.length - 1 != i) {
_array4.push(",");
}
}
texto2 =_array4.reverse().concat(".").concat( _array [1]).join("");
}
-
You don't separate the numbers after the point in that.
-
-
I missed that, why do you want to format the one and not the other?
123,456,789.234896
looks odd compared with
123,456,789.234,896
-
well i dont know in other parts but in mexico when your are working with currency numbers you dont separate with comas the numbers after the dot.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|