note 62839 added to function.strval

From: Date: Fri, 10 Mar 2006 16:15:10 +0000
Subject: note 62839 added to function.strval
Groups: php.notes 
Request: Send a blank email to php-notes+get-105217@lists.php.net to get a copy of this message
In complement to Tom Nicholson's contribution, here is the french version (actually it's possible to change the language, but you should check the syntax ;) ) function int_to_words($x) { global $nwords; if(!is_numeric($x)) $w = '#'; else if(fmod($x, 1) != 0) $w = '#'; else { if($x < 0) { $w = $nwords['minus'].' '; $x = -$x; } else $w = ''; // ... now $x is a non-negative integer. if($x < 21) // 0 to 20 $w .= $nwords[$x]; else if($x < 100) { // 21 to 99 $w .= $nwords[10 * floor($x/10)]; $r = fmod($x, 10); if($r > 0) $w .= '-'. $nwords[$r]; } else if($x < 1000) { // 100 to 999 $w .= $nwords[floor($x/100)] .' '.$nwords['hundred']; $r = fmod($x, 100); if($r > 0) $w .= ' '.$nwords['separator'].' '. int_to_words($r); } else if($x < 1000000) { // 1000 to 999999 $w .= int_to_words(floor($x/1000)) .' '.$nwords['thousand']; $r = fmod($x, 1000); if($r > 0) { $w .= ' '; if($r < 100) $w .= $nwords['separator'].' '; $w .= int_to_words($r); } } else { // millions $w .= int_to_words(floor($x/1000000)) .' '.$nwords['million']; $r = fmod($x, 1000000); if($r > 0) { $w .= ' '; if($r < 100) $word .= $nwords['separator'].' '; $w .= int_to_words($r); } } } return $w; } // Usage in English $nwords = array( "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", 30 => "thirty", 40 => "forty", 50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty", 90 => "ninety" , "hundred" => "hundred", "thousand"=> "thousand", "million"=>"million", "separator"=>"and", "minus"=>"minus"); echo 'There are currently '. int_to_words(-120223456) . ' members logged on.<br>'; //Utilisation en Francais $nwords = array( "zéro", "un", "deux", "trois", "quatre", "cinq", "six", "sept", "huit", "neuf", "dix", "onze", "douze", "treize", "quatorze", "quinze", "seize", "dix-sept", "dix-huit", "dix-neuf", "vingt", 30 => "trente", 40 => "quarante", 50 => "cinquante", 60 => "soixante", 70 => "soixante-dix", 80 => "quatre-vingt", 90 => "quatre-vingt-dix" , "hundred" => "cent", "thousand"=> "mille", "million"=>"million", "separator"=>"", "minus"=>"moins"); echo 'Il y a actuellement '. int_to_words(-120223456) . ' membres connectés.<br>'; ---- Server IP: 84.18.202.180 Probable Submitter: 81.31.126.130 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.strval.php Edit -- http://master.php.net/note/edit/62839 Del: integrated -- http://master.php.net/note/delete/62839/integrated Del: useless -- http://master.php.net/note/delete/62839/useless Del: bad code -- http://master.php.net/note/delete/62839/bad+code Del: spam -- http://master.php.net/note/delete/62839/spam Del: non-english -- http://master.php.net/note/delete/62839/non-english Del: in docs -- http://master.php.net/note/delete/62839/in+docs Del: other reasons-- http://master.php.net/note/delete/62839 Reject -- http://master.php.net/note/reject/62839 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#105217) next »