# script_name: numbers_to_chinese # usage: perl number2_to_chinese.pl 30806 # result: 三万零八百零六 my %cn_numbers=( 1=>"一", 2=>"二", 3=>"三", 4=>"四", 5=>"五", 6=>"六", 7=>"七", 8=>"八", 9=>"九", ); my $number=shift; my $cn_number; if ($number>=10000){ my $n=$number/10000; $n=~s/\..*//; $cn_number=$cn_numbers{$n}."万"; $number=$number % 10000; } if ($number>=1000){ my $n=$number/1000; $n=~s/\..*//; $cn_number.=$cn_numbers{$n}."千"; $number=$number % 1000; } if ($number>=100){ my $n=$number/100; $n=~s/\..*//; $cn_number.=$cn_numbers{$n}."百"; $number=$number % 100; } if ($number>=10){ my $n=$number/10; $n=~s/\..*//; $cn_number.=$cn_numbers{$n}."十"; $number=$number % 10; } if ($number>0){ $cn_number.=$cn_numbers{$number}; } #补零 if ($cn_number=~/万/ && $cn_number!~/千/){ $cn_number=~s/万/万零/; } if ($cn_number=~/千/ && $cn_number!~/百/){ $cn_number=~s/千/千零/; } if ($cn_number=~/百/ && $cn_number!~/十/){ $cn_number=~s/百/百零/; } $cn_number=~s/一十/十/g; print "$cn_number\n";

In reply to english numbers to chinese numbers by changlehu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.