zoltar Posted July 30, 2004 Report Posted July 30, 2004 Baigi vajadzētu skriptiņu, kas izdod summu piem. naudai ar vārdiem no kautkādas float vērtības ar atbilstošu gramatikas loģiku latviešu valodai. Nav kāds jau saskāries ar šito?
Kaklz Posted July 30, 2004 Report Posted July 30, 2004 http://php.lv/f/index.php?showtopic=825&hl=summa
zoltar Posted July 30, 2004 Author Report Posted July 30, 2004 (edited) Kauto uzkodeeju ar bezjeedziigi daudz liekiem switchiem :) class to_words_lv{ var $_sep = ' '; var $_digits = array( 0 => 'nulle', 'vien', 'div', 'trĆ®s', 'Ä?etr', 'piec', 'seÅ', 'septiņ', 'astoņ', 'deviņ' ); function toWords($num) { $ret = ''; $num = intval($num); if($num > 9999){ return $num; } $num = trim((string)$num); $num = preg_replace('/^0+/','',$num); $th = $h = $t = $d = 0; switch(strlen($num)) { case 4: $th = (int)substr($num,-4,1); case 3: $h = (int)substr($num,-3,1); case 2: $t = (int)substr($num,-2,1); case 1: $d = (int)substr($num,-1,1); break; case 0: return; break; } switch ($th) { case 0: break; case 1: $ret .= $this->_sep. 'tÅ«kstoÅ'; break; default: $ret .= $this->_sep . $this->_digits[$th] . 'tÅ«kstoÅ'; break; } switch ($h) { case 0: break; case 1: $ret .= $this->_sep. 'simt'; break; default: $ret .= $this->_sep . $this->_digits[$h] . 'simt'; break; } $pd = true; switch ($t) { case 0: break; case 1: $ret .= $this->_sep . $this->_digits[$d] . 'padsmit'; $pd = false; break; default: $ret .= $this->_sep . $this->_digits[$t] . 'desmit'; break; } if($pd){ switch ($d) { case 0: break; case 1: $ret .= $this->_sep . $this->_digits[$d] . 's'; break; default: $ret .= $this->_sep . $this->_digits[$t] . 'i'; break; } } return $ret; } } Cerams ka nevienam reekjinus liekaakus par 9k nevajadzees automaataa rakstiit :) Vispaar ir PEAR klase toWords, kur viss ir daudz korektaak ar pakaapeem utt., tikai nav latvieshu valodai (ee un lt ir :) ) Edited July 30, 2004 by zoltar
Recommended Posts