#!/usr/bin/perl use strict; use warnings; print (numformat(1000000),"\n"); print (numformat(123),"\n"); print (numformat(12),"\n"); sub numformat { my ($num) = @_; die "'$num' is not a simple integer" unless $num =~ /^\d+$/; while ($num =~ s/(\d)(\d\d\d)(?!\d)/$1,$2/) {}; return $num; }
In reply to Re: Formatting a number
by Molt
in thread Formatting a number
by harryf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |