34 users online (1 members and 33 guests)  


  Results 1 to 2 of 2

Related

  1. How to round numbers    Forum: CGI Perl Forum
    Replies: 6
  1. #1
    blink's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    19

    How to format Mb numbers?

    Hello,

    If I have a number of 123456789, how do I reformat it to be shown as 123,456,789?

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hi,

    I'm not so hot on perl, but some googling found this sub, designed for formatting to currencies:

    Code:
    sub CommaFormatted
    {
    	my $delimiter = ','; # replace comma if desired
    	my($n,$d) = split /\./,shift,2;
    	my @a = ();
    	while($n =~ /\d\d\d\d/)
    	{
    		$n =~ s/(\d\d\d)$//;
    		unshift @a,$1;
    	}
    	unshift @a,$n;
    	$n = join $delimiter,@a;
    	$n = "$n\.$d" if $d =~ /\d/;
    	return $n;
    }
    # end of subroutine CommaFormatted
    Source: http://www.web-source.net/web_develo...formatting.htm
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread