#!/usr/bin/perl -w use strict; use utf8; #/=======================================================================\ #| Copyright (C) 2008 Ioan A. Sucan, Wanding Zhou | #| This program converts numbers up to one thousand billion into Chinese | #| Released under the GNU General Public License | #|-----------------------------------------------------------------------| #| Wanding Zhou | #| http://ioan.sucan.info | #\=======================================================================/ my %numbers=(0=>'零',1=>'一',2=>'二',3=>'三',4=>'四', 5=>'五',6=>'六',7=>'七',8=>'八',9=>'九'); use constant TEN => 10; use constant HUNDRED => 100; use constant THOUSAND => 1000; use constant TEN_THOUSAND => 1000_0; use constant HUNDRED_MILLION => 10_000_000; use constant THOUSAND_MILLION => 100_000_000; use constant THOUSAND_BILLION => 1000_000_000_000; my $ten_marker=0; sub convert { my ($nr)=@_; return $numbers{$nr} if $nr < TEN; if($nr=TEN ? '百' : '百零').convert($rest); } if($nrHUNDRED ? '千':'千零').convert($rest); } if($nrTHOUSAND ? '万' :'万零').convert($rest); } if($nrHUNDRED_MILLION ? '亿':'亿零').convert($rest); } '无穷大'; } my $nr = ; chomp($nr); binmode STDOUT,":utf8"; print $nr<0 ? '负'.convert(-$nr) : convert($nr)."\n";