Number formatting doubt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lilly07
    New Member
    • Jul 2008
    • 89

    Number formatting doubt

    Hi,

    I get to get a number 3076569 along a flow in my program which needs to be displayed in a html page. How to change the formatting into 3,00,76,569 as human readable? Any staraight forward method or I need to count the digit and out a comma? Thanks.
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    perl add commas to number ;)

    hehehe.... just noticed my code snippet on Daniweb comes up second in that google search. :^D

    Comment

    • Icecrack
      Recognized Expert New Member
      • Sep 2008
      • 174

      #3
      I guess i will post the code for this place but Kevin also gave you the answer.


      Code:
      $num = 3076569;
      $num = Format($num);
       
      sub Format {
         ($a = shift) =~ s/\G(\d{1,3})(?=(?:\d\d\d)+(?:\.|$))/$1,/g; 
         return $a; 
      }
      
      print "$num";

      Comment

      • lilly07
        New Member
        • Jul 2008
        • 89

        #4
        Yes Thanks. I got Kevin's code.

        Comment

        Working...