A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: Numbers with "," and "."

  1. #1

    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

  2. #2
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    dollars = 10;
    cents = 56;


    dollars +=10;
    money_display = "$"+dollars+"."+cents;

    trace(money_display);

  3. #3
    thanks but my question is more like how can i convert and input like 20000 to 20,000.

    Thanks

  4. #4
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    Originally posted by oldnewbie
    dollars +=10;
    dollars *=10;

  5. #5
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    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.

  6. #6
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    sorry... let me fix that.

  7. #7

  8. #8
    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("");
    }

  9. #9
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Send it to George!

  10. #10
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    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);

  11. #11
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    oh... I could have done that, you said you wanted decimals too

  12. #12
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Send both to George!

  13. #13
    Developer
    Join Date
    Sep 2001
    Location
    The Bluegrass State Will Flash For Food ™
    Posts
    3,789
    Originally posted by oldnewbie
    Send both to George!
    In the mail...

  14. #14
    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

  15. #15
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    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(numdecimalplaces) {
        var 
    before_the_point;
        var 
    after_the_point;
        var 
    _array;
        var 
    _output;
        
    after_the_point num.toString().split(".")[1];
        switch (
    decimalplaces) {
        case 
    :
            
    num Math.round(num);
            
    after_the_point "";
        case 
    undefined :
            break;
        default :
            
    after_the_point Number("0."+after_the_point);
            
    after_the_point *= Math.pow(10decimalplaces);
            
    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 
    0i<_itmaxi++) {
            if (!(
    i%3) && i>0) {
                
    _array2.push(",");
            }
            
    _array2.push(_array.pop());
        }
        return 
    _array2;
    }
    trace(format_number(123456789.2980));
    trace(format_number(369.980));
    trace(format_number(2468.123456));
    trace(format_number(123456789.20)); 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center