go ahead... be a heretic PerlMonks

### comment on

 Need Help??
Hi,

(Now I call *this* node archaeology)

this is for german, very dumb. But a nice recursive aproach, suitable for numbers up to 999 999 999 with nice german grammar. Easily extendable.

```sub de_number {
my \$positive = shift;
my \$out;

my @tokens1 = qw(null ein zwei drei vier fünf sechs sieben acht ne
+un zehn elf zwölf);
my @tokens2 = qw(zwanzig dreissig vierzig fünfzig sechzig siebzig
+achtzig neunzig hundert);
#    my @tokens3 = qw(million milliarde billion billiarde); # Not need
+ed now

if(\$positive >= 0 && \$positive <= 12) {
\$out = \$tokens1[\$positive];
} elsif(\$positive >= 13 && \$positive <= 19) {
\$out = \$tokens1[\$positive-10].'zehn';
} elsif(\$positive >= 20 && \$positive <= 100) {
my \$one_idx = int \$positive/10-2;
my \$ten_idx = \$positive-(\$one_idx+2)*10;

\$out = \$tokens1[\$ten_idx].'und' if \$ten_idx;
\$out .= \$tokens2[\$one_idx];
} elsif(\$positive >= 101 && \$positive <= 999) {
my \$one_idx = int \$positive/100;

\$out = \$tokens1[\$one_idx].'hundert'.&de_number(\$positive-\$one_idx*
+100);
} elsif(\$positive >= 1000 && \$positive <= 999999) {
my \$one_idx = int \$positive/1000;
my \$tausend = \$positive-\$one_idx*1000;
my \$nonull = \$tausend ? &de_number(\$tausend) : '';

\$out = &de_number(\$one_idx).'tausend'.\$nonull;
} elsif(\$positive >= 1000000 && \$positive <= 999999999) {
my \$one_idx = int \$positive/1000000;
my \$mio     = \$positive-\$one_idx*1000000;
my \$nonull  = \$mio ? ' '.&de_number(\$mio) : '';
my \$one     = \$one_idx == 1 ? 'e' : '';

\$out = &de_number(\$one_idx).\$one.' million';
\$out .= 'en' if \$one_idx > 1;
\$out .= \$nonull;
}

return \$out;

}

Bye
PetaMem

In reply to Re: number 2 text by PetaMem
in thread number 2 text by Prince99

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

• Are you posting in the right place? Check out Where do I post X? to know for sure.
• Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
• Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
• Want more info? How to link or How to display code and escape characters are good places to start.

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2023-03-26 16:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Which type of climate do you prefer to live in?

Results (63 votes). Check out past polls.

Notices?