hmm... my comment was lost... I added wàn (1'0000) and shíwàn (10'0000)

I liked it very much, though I saw some discrepancies on the web (I do not know Chinese... just doing it by websites)

This website seems to translate the Chinese characters into something else...

my $number=shift; print "Received Number($number)";

@CN_NUMBERS = qw(零 一 二 三 四 五 六 七 八 九); my %cn_numbers= map {$_ => $CN_NUMBERS[$_]} 0..$#CN_NUMBERS;

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]; }

print "UNDEFINED" unless(defined $cn_number); $cn_number .= $CN_NUMBERS[0] unless(defined $cn_number); print "!!!!()\n";

# 1,000: 千 (仟) qiān if ($cn_number=~/万/ && $cn_number!~/千/){ $cn_number=~s/万/万零/; }

# 10,000: 万 (萬) wàn (1'0000) if ($cn_number=~/千/ && $cn_number!~/百/){ $cn_number=~s/千/千零/; }

# 100,000: 十万 (萬) shíwàn (10'0000) if ($cn_number=~/百/ && $cn_number!~/十/){ $cn_number=~s/百/百零/; }

$cn_number=~s/一十/十/g; print "$cn_number\n";

edit: used pre and to mask the [] for arrays I used code


In reply to Re: english numbers to chinese numbers by FreeBeerReekingMonk
in thread 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.