Pereiti prie turinio

Sumos skaiciais pavertimas i suma zodziais, lietuviskai


Rekomenduojami pranešimai

  • Administratoriai
Sveiki,

 

susiduriau su tokia problemele, kad reikia suma skaiciais paversti i suma zodziais ir lietuviskai. Kazkaip numanau, kad tikrai ne vienas turejo gaminti sita dalykeli, tad gal yra cia tokiu ? ;)

 

Gal kažką tokio turėjai galvoje? ;)

function galune($skaicius, $vienas, $du, $desim) {
	if (substr($skaicius,-1,1) == 0 || (substr($skaicius,-2,2) >= 10 && substr($skaicius,-2,2) <= 20)) return $desim;
	elseif (substr($skaicius,-1,1) >= 2 && substr($skaicius,-1,1) <= 9) return $du;
	else return $vienas;
}

 

Arba šis senokai naudotas, bet pasikeitus bei papildžius gal kas ir išeitų

 

/*
(c) ARIUS DESIGN
*/
function daugiskaita($nr,$word=''){
$sk = substr($nr, -1);
if($sk == 1){
	$word = $word.'as';
} else if ($sk == 0) {
	$word = $word.'ų';
} else if (in_array($sk, range('2','9'))) {
	$word = $word.'ai';
}
return sprintf('Iš viso: %d %s', $nr, $word);
}

echo daugiskaita('1','komentar')." naujienose,<br />";

Redagavo Arius
Nuoroda į pranešimą
Dalintis kituose puslapiuose
  • po 2 mėnesių...

Tokį naudoju:

 

function convert_number($number){ 
$kn = floor($number / 1000);
$number -= $kn * 1000; 
$Hn = floor($number / 100); 
$number -= $Hn * 100; 
$Dn = floor($number / 10);
$n = $number % 10;

$res = ""; 

if ($kn) 
{ 
		if($kn == 1){
			$res .= "tūkstantis";
		}	
		else {
			$res .= (empty($res) ? "" : " ") . convert_number($kn);
			if(substr($kn, -1) == "0" || (substr($kn, -2) > 10 && substr($kn, -2) < 20)){
				$res .= " tūkstančių";
			}
			elseif(substr($kn, -1) == 1){
				$res .= " tūkstantis";
			}
			else {
				$res .= " tūkstančiai"; 
			}
		}
} 

if ($Hn) 
{ 
		if($Hn == 1){
			$res .= " šimtas";
		}
		else {
			$res .= (empty($res) ? "" : " ") . convert_number($Hn) . " šimtai";
		}
} 

$ones = array("", "vienas", "du", "trys", "keturi", "penki", "šeši", "septyni", "aštuoni", "devyni", "dešimt", "vienuolika", "dvylika", "trylika", "keturiolika", "penkiolika", "šešiolika", "septyniolika", "aštuoniolika", "devyniolika"); 
$tens = array("", "", "dvidešimt", "trisdešimt", "keturiasdešimt", "penkiasdešimt", "šešiasdešimt", "septyniasdešimt", "aštuoniasdešimt", "devyniasdešimt"); 

if ($Dn || $n) 
{ 
	if (!empty($res)) 
	{ 
		$res .= " "; 
	} 

	if ($Dn < 2) 
	{ 
		$res .= $ones[$Dn * 10 + $n]; 
	} 
	else 
	{ 
		$res .= $tens[$Dn]; 

		if ($n) 
		{ 
			$res .= " " .$ones[$n]; 
		} 
	} 
} 
return $res; 
}

$skaicius = 5106;
$zodziais = convert_number($skaicius);

echo $zodziais;

 

Pritaikytas iki 999 tūkstančių.

Nuoroda į pranešimą
Dalintis kituose puslapiuose

<?
function sk_to_lt($d) {

list($l, $centai) = explode(".", $d);

 $sk1000[0] = "tūkstantis ";
 $sk1000[1] = "tūkstančiai ";
 $sk1000[2] = "tūkstančių ";


 $sk1000000[0] = "milijonas ";
 $sk1000000[1] = "milijonai ";
 $sk1000000[2] = "milijonų ";



 $minus = "minus ";

 $skaiz = "";


 if ($l < 0) {
$skaiz = $skaiz . $minus;
$l1 = $l*(-1); 
 }

 else $l1 = $l;


// skaidom skaiciu

 $lv = $l1; 



 settype($lv,"integer"); 

 for ($i = 8; $i >= 0; $i--) {

$ls =(integer)( $lv / 10);

$ll = $lv % 10;

$ld[$i] = $ll;

$lv = $ls; 



}



// rasom zodzius

 $skaiz = $skaiz . simtai($ld[0],$ld[1],$ld[2]);



// milijonai

 if ($ld[1] <> 1 and $ld[2] == 1)

$skaiz = $skaiz . $sk1000000[0];

 if ($ld[1] <> 1 and $ld[2] <> 1 and $ld[2] <> 0)

$skaiz = $skaiz . $sk1000000[1];

 if ($ld[1] == 1 and $ld[2] <> 0)

$skaiz = $skaiz . $sk1000000[2];

 if (($ld[0] <> 0 or $ld[1] <> 0) and $ld[2] == 0)

$skaiz = $skaiz . $sk1000000[2];



 $skaiz = $skaiz . simtai($ld[3],$ld[4],$ld[5]);



// tukstanciai

 if ($ld[4] <> 1 and $ld[5] == 1)

$skaiz = $skaiz . $sk1000[0];

 if ($ld[4] <> 1 and $ld[5] <> 1 and $ld[5] <> 0)

$skaiz = $skaiz . $sk1000[1];

 if ($ld[4] == 1 and $ld[5] <> 0)

$skaiz = $skaiz . $sk1000[2];

 if (($ld[3] <> 0 or $ld[4] <> 0) and $ld[5] == 0)

$skaiz = $skaiz . $sk1000[2];



 $skaiz = $skaiz . simtai($ld[6],$ld[7],$ld[8]);


$last .= $skaiz;

$l_chars = array_reverse ( str_split ( $l ) );
//print_r ( $l_chars );
$desimtys_tomo = (int) $l_chars [ 1 ] . $l_chars [ 0 ];
if ( $l_chars [ 0 ] == '0' or ($desimtys_tomo >= 10 and $desimtys_tomo <= 20))
{
$last .= " litų";
}

elseif ( $desimtys_tomo == 1 or ($l_chars [ 0 ] == '1' and $desimtys_tomo != 11) )
{
$last .= " litas";
}

else
{
$last .= " litai";
}

if ( $centai > 0 )
{
$centai_chars = str_split ( $centai );
if ( $centai_chars [ 0 ] == '0' )
{
	$centai = (int) $centai [ 1 ];
}
$last .= " ir ". $centai;

if ( $centai == 1 or ($centai_chars [ 1 ] == '1' and $centai != 11 ) )
{
	$last .= ' centas';
}
elseif ( $centai_chars [ 1 ] == '0' or ($centai >= 10 and $centai <= 20))
{
	$last .= ' centų';
}
else
{
	$last .= " centai";
}
}
 return ucfirst ($last); 

 }



function simtai($s,$d,$v) {



 $sk1[0] = "vienas ";

 $sk1[1] = "du ";

 $sk1[2] = "trys ";

 $sk1[3] = "keturi ";

 $sk1[4] = "penki ";

 $sk1[5] = "šeši ";

 $sk1[6] = "septyni ";

 $sk1[7] = "aštuoni ";

 $sk1[8] = "devyni ";

 $sk1[9] = "dešimt ";



 $sk11[0] = "vienuolika ";

 $sk11[1] = "dvylika ";

 $sk11[2] = "trylika ";

 $sk11[3] = "keturiolika ";

 $sk11[4] = "penkiolika ";

 $sk11[5] = "šešiolika ";

 $sk11[6] = "septyniolika ";

 $sk11[7] = "aštuoniolika ";

 $sk11[8] = "devyniolika ";

 $sk11[9] = "dvidešimt ";



 $sk10[0] = "dešimt ";

 $sk10[1] = "dvidešimt ";

 $sk10[2] = "trisdešimt ";

 $sk10[3] = "keturiasdešimt ";

 $sk10[4] = "penkiasdešimt ";

 $sk10[5] = "šešiasdešimt ";

 $sk10[6] = "septyniasdešimt ";

 $sk10[7] = "aštuoniasdešimt ";

 $sk10[8] = "devyniasdešimt ";

 $sk10[9] = "šimtas ";



 $sk100[0] = "šimtas ";

 $sk100[1] = "šimtai ";







 $simtz = "";



 if ($s <> 0) {

$simtz = $simtz . $sk1[$s-1];

if ($s == 1)

  $simtz = $simtz . $sk100[0];

else

  $simtz = $simtz . $sk100[1];

}



 if ($d <> 0) {

if ($d <> 1 or $v == 0)

  $simtz = $simtz . $sk10[$d-1];

}



 if ($v <> 0) {

if ($d == 1)

  $simtz = $simtz . $sk11[$v-1];

else

  $simtz = $simtz . $sk1[$v-1];

}



 return $simtz;

 }  

?>

Kiek galingesnis daikčiukas, radau tarp senų php.lt archyvų, dar tomaz padėjo patvarkyti. Dėkui jam.

Nuoroda į pranešimą
Dalintis kituose puslapiuose
  • Administratoriai

Dar toki griozdą turiu, gal kam pravers ir pasitaisys kaip norės

 

<?php

/** Serialized Array of big names, thousand, million, etc 
* @package NumberToText */
define("N2T_BIG", serialize(array('thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion', 'nonillion', 'decillion', 'undecillion', 'duodecillion', 'tredecillion', 'quattuordecillion', 'quindecillion', 'sexdecillion', 'septendecillion', 'octodecillion', 'novemdecillion', 'vigintillion', 'unvigintillion', 'duovigintillion', 'trevigintillion', 'quattuorvigintillion', 'quinvigintillion', 'sexvigintillion', 'septenvigintillion', 'octovigintillion', 'novemvigintillion', 'trigintillion', 'untrigintillion', 'duotrigintillion', 'tretrigintillion', 'quattuortrigintillion', 'quintrigintillion', 'sextrigintillion', 'septentrigintillion', 'octotrigintillion', 'novemtrigintillion')));
/** Serialized Array of medium names, twenty, thirty, etc 
* @package NumberToText */
define("N2T_MEDIUM", serialize(array(2=>'twenty', 3=>'thirty', 4=>'fourty', 5=>'fifty', 6=>'sixty', 7=>'seventy', 8=>'eighty', 9=>'ninety'))); 
/** Serialized Array of small names, zero, one, etc.. up to eighteen, nineteen 
* @package NumberToText */
define("N2T_SMALL", serialize(array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen')));
/** Word for "dollars" 
* @package NumberToText */
define("N2T_DOLLARS", "dollars");
/** Word for one "dollar" 
* @package NumberToText */
define("N2T_DOLLARS_ONE", "dollar");
/** Word for "cents" 
* @package NumberToText */
define("N2T_CENTS", "cents");
/** Word for one "cent" 
* @package NumberToText */
define("N2T_CENTS_ONE", "cent");
/** Word for "and" 
* @package NumberToText */
define("N2T_AND", "and");
/** Word for "negative" 
* @package NumberToText */
define("N2T_NEGATIVE", "negative");

/** Number to text converter. Converts a number into a textual description, such as
* "one hundred thousand and twenty-five".
* 
* Now supports _any_ size number, and negative numbers. To pass numbers > 2 ^32, you must
* pass them as a string, as PHP only has 32-bit integers.
*
* @author Greg MacLelan
* @version 1.1
* @param int  $number	  The number to convert
* @param bool $currency	True to convert as a dollar amount
* @param bool $capatalize  True to capatalize every word (except "and")
* @param bool $and		 True to use "and"  (ie. "one hundred AND six")
* @return The textual description of the number, as a string.
* @package NumberToText
*/
/** Changelog:
* 2007-01-11: Fixed bug with invalid array references, trim() output
*/
function NumberToText($number, $currency = false, $capatalize = false, $and = true) {
$big = unserialize(N2T_BIG);
$small = unserialize(N2T_SMALL);

// get rid of leading 0's
/*
while ($number{0} == 0) {
	$number = substr($number,1);
}
*/

$text = "";

//$negative = ($number < 0); // check for negative
//$number = abs($number); // make sure we have a +ve number
if (substr($number, 0, 1) == "-") {
	$negative = true;
	$number = substr($number,1); // abs()
} else {
	$negative = false;
}

// get the integer and decimal parts
//$int_o = $int = floor($number); // store into two vars
if ($pos = strpos($number,".")) {
	$int_o = $int = substr($number,0,$pos);
	$decimal_o = $decimal = substr($number,$pos + 1);
} else {
	$int_o = $int = $number;
	$decimal_o = $decimal = 0;
}
// $int_o and $decimal_o are for "original value"

// conversion for integer part:

$section = 0; // $section controls "thousand" "million" etc
do {
	// keep breaking down into 3 digits ($convert) and the rest
	//$convert = $int % 1000;
	//$int = floor($int / 1000);

	if ($section > count($big) - 1) {
		// ran out of names for numbers this big, call recursively
		$text = NumberToText($int, false, false, $and)." ".$big[$section-1]." ".$text;
		$int = 0;
	} else { 
		// we can handle it

		$convert = substr($int, -3); // grab the last 3 digits
		$int = substr($int, 0, -1 * strlen($convert));

		if ($convert > 0) {
			// we have something here, put it in
			$text = trim(n2t_convertthree($convert, $and, ($int > 0)).(isset($big[$section-1]) ? ' '.$big[$section-1].' ' : '').$text);
		}
	}

	$section++;
} while ($int > 0);


// conversion for decimal part:

if ($currency && floor($number)) {
	// add " dollars"
	$text .= " ".($int_o == 1 ? N2T_DOLLARS_ONE : N2T_DOLLARS)." ";
}

if ($decimal && $currency) {
	// if we have any cents, add those
	if ($int_o > 0) {
		$text .= " ".N2T_AND." ";
	}

	$cents = substr($decimal,0,2); // (0.)2342 -> 23
	$decimal = substr($decimal,2); // (0.)2345.. -> 45..

	$text .= n2t_convertthree($cents, false, true); // explicitly show "and" if there was an $int
}

if ($decimal) {
	// any remaining decimals (whether or not $currency is set)
	$text .= " point";
	for ($i = 0; $i < strlen($decimal); $i++) {
		// go through one number at a time
		$text .= " ".$small[$decimal{$i}];
	}
}

if ($decimal_o && $currency) {
	// add " cents" (if we're doing currency and had decimals)
	$text .= " ".($decimal_o == 1 ? N2T_CENTS_ONE : N2T_CENTS);
}

// check for negative
if ($negative) {
	$text = N2T_NEGATIVE." ".$text;
}

// capatalize words
if ($capatalize) {
	// easier to capatalize all words then un-capatalize "and"
	$text = str_replace(ucwords(N2T_AND), N2T_AND, ucwords($text));
}

return trim($text);
}

/** This is a utility function of n2t. It converts a 3-digit number
* into a textual description. Normally this is not called by itself.
*
* @param  int  $number	 The 3-digit number to convert (0 - 999)
* @param  bool $and		True to put the "and" in the string
* @param  bool $preceding  True if there are preceding members, puts an
*						  explicit and in (ie 1001 => one thousand AND one)
* @return The textual description of the number, as a string 
* @package NumberToText
*/
function n2t_convertthree($number, $and, $preceding) {
$small = unserialize(N2T_SMALL);
$medium = unserialize(N2T_MEDIUM);

$text = "";

if ($hundreds = floor($number / 100)) {
	// we have 100's place
	$text .= $small[$hundreds]." hundred ";
}
$tens = $number % 100;
if ($tens) {
	// we still have values
	if ($and && ($hundreds || $preceding)) {
		$text .= " ".N2T_AND." ";
	}

	if ($tens < 20) {
		$text .= $small[$tens];
	} else {
		$text .= $medium[floor($tens/10)];
		if ($ones = $tens % 10) {
			$text .= "-".$small[$ones];
		}
	}
}

return $text;
}

function getmicrotime(){ 
list($usec, $sec) = explode(" ",microtime()); 
return ((float)$usec + (float)$sec); 
} 


$currency = isset($_GET["currency"]) ? (bool)$_GET["currency"] : false;
$capatalize = isset($_GET["capatalize"]) ? (bool)$_GET["capatalize"] : false;
$and = isset($_GET["and"]) ? (bool)$_GET["and"] : !isset($_GET["num"]); // set to true by default if we didnt submit anything

echo "<form method=\"GET\">";
echo "<input type=text name=\"num\" value=\"".$_GET["num"]."\">";
echo "<input type=submit value=\"Convert\">";
echo "<br><input type=checkbox name=\"currency\" value=\"1\" ".($currency ? "CHECKED" :"")."> Currency";
echo "<br><input type=checkbox name=\"capatalize\" value=\"1\" ".($capatalize ? "CHECKED" :"")."> Capatalize";
echo "<br><input type=checkbox name=\"and\" value=\"1\" ".($and ? "CHECKED" :"")."> Use 'and'";
echo "</form>";

if (isset($_GET['num'])) {
$num = preg_replace('/[^0-9\.]/','',$_GET['num']);
echo $num . " => ".numbertotext($num, $currency, $capatalize, $and);
echo "<br><br><br><br>";
exit;
} 

$arr = array(1,2,10,11,12,20,21,100,200,202,220,223,1000,1100,1232,10000,100000,1100000,1
000001,1.1,1.23,1.424,1.3005,0.1,0.23,23445.34,349.35,3476233.52); 
echo "Normal:<br><br>";

$time_start = getmicrotime();
foreach ($arr as $val) {
//echo number_format($val,6)." => ".numbertotext($val,false,false)."<br>";
echo $val." => \"".numbertotext($val,false,false)."\"<br>";
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "Completed in $time";

echo "<br><br><br>Currency:<br><br>";

$time_start = getmicrotime();
foreach ($arr as $val) {
//echo number_format($val,6)." => ".numbertotext($val,true,true)."<br>";
echo $val." => ".numbertotext($val,true,true)."<br>";
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "Completed in $time";


echo "<br><br><br>";


$arr = array(-1,-32754264,7823572834.23432,"842673284525.3253",-69,1000000000,10000000000,100000000000,"1000000000000","10000000000000","100000000000000","1000000000000000","10000000000000000","100000000000000000","1000000000000000000","1000000000000000000000","1000000000000000000000000","1000000000000000000000000000","1000000000000000000000000000000","1000000000000000000000000000000000","1000000000000000000000000000000000000","1000000000000000000000000000000000000000","1000000000000000000000000000000000000000000","1000000000000000000000000000000000000000000000","1000000000000000000000000000000000000000000000000","1000000000000000000000000000000000000000000000000000","1000000000000000000000000000000000000000000000000000000","1000000000000000000000000000000000000000000000000000000000","1000000000000000000000000000000000000000000000000000000000000","1000000000000000000000000000000000000000000000000000000000000000","1000000000000000000000000000000000000000000000000000000000000000000","1735493936528346132019285410348712730057341562931024518346213403490","-8365102934619034174538361493275960273462592739257246349237426342384.38651","1000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000");
echo "Normal:<br><br>";

$time_start = getmicrotime();
foreach ($arr as $val) {
//echo number_format($val,6)." => ".numbertotext($val,false,false)."<br>";
echo $val." => ".numbertotext($val,false,false)."<br>";
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "Completed in $time";

echo "<br><br><br>Currency:<br><br>";

$time_start = getmicrotime();
foreach ($arr as $val) {
//echo number_format($val,6)." => ".numbertotext($val,true,true)."<br>";
echo $val." => ".numbertotext($val,true,true)."<br>";
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "Completed in $time";


?>

Nuoroda į pranešimą
Dalintis kituose puslapiuose
  • po 7 metų...

Prikeliu :) Kas gali padėti, faktūruose verčia skaičių sumą lietuviškais žodžiais gerai, bet eurus bei centus angliškai, PVZ: penki euros 40 cents, naudoju "Opencart" 2.2 , faktūrų modulis "PDF Invoice Pro" supportas sakė problemos ieškoti \system\library\numbers_words\Words\Locale\lt.php

Redagavo zuzlik
Nuoroda į pranešimą
Dalintis kituose puslapiuose

Kur?

 

<?php
/**
* Numbers_Words
*
* PHP version 5
*
* Copyright (c) 1997-2006 The PHP Group
*
* This source file is subject to version 3.01 of the PHP license,
* that is bundled with this package in the file LICENSE, and is
* available at through the world-wide-web at
* http://www.php.net/license/3_01.txt
* If you did not receive a copy of the PHP license and are unable to
* obtain it through the world-wide-web, please send a note to
* [email protected] so we can mail you a copy immediately.
*
* @category Numbers
* @package  Numbers_Words
* @author   Laurynas Butkus <[email protected]>
* @license  PHP 3.01 http://www.php.net/license/3_01.txt
* @version  SVN: $Id$
* @link     http://pear.php.net/package/Numbers_Words
*/

/**
* Class for translating numbers into Lithuanian.
*
* @author Laurynas Butkus
* @package Numbers_Words
*/

/**
* Include needed files
*/
// require_once "Numbers/Words.php";

/**
* Class for translating numbers into Lithuanian.
*
* @category Numbers
* @package  Numbers_Words
* @author   Laurynas Butkus <[email protected]>
* @license  PHP 3.01 http://www.php.net/license/3_01.txt
* @link     http://pear.php.net/package/Numbers_Words
*/
class Numbers_Words_Locale_lt extends Numbers_Words
{

   // {{{ properties

   /**
    * Locale name
    * @var string
    * @access public
    */
   var $locale = 'lt';

   /**
    * Language name in English
    * @var string
    * @access public
    */
   var $lang = 'Lithuanian';

   /**
    * Native language name
    * @var string
    * @access public
    */
   var $lang_native = 'lietuviškai';

   /**
    * The word for the minus sign
    * @var string
    * @access private
    */
   var $_minus = 'minus'; // minus sign

   /**
    * The sufixes for exponents (singular and plural)
    * @var array
    * @access private
    */
   var $_exponent = array(
       0 => array(''),
       3 => array('tūkstantis','tūkstančiai','tūkstančių'),
       6 => array('milijonas','milijonai','milijonų'),
       9 => array('bilijonas','bilijonai','bilijonų'),
      12 => array('trilijonas','trilijonai','trilijonų'),
      15 => array('kvadrilijonas','kvadrilijonai','kvadrilijonų'),
      18 => array('kvintilijonas','kvintilijonai','kvintilijonų')
       );

   /**
    * The array containing the digits (indexed by the digits themselves).
    * @var array
    * @access private
    */
   var $_digits = array(
       0 => 'nulis', 'vienas', 'du', 'trys', 'keturi',
       'penki', 'šeši', 'septyni', 'aštuoni', 'devyni'
   );

   /**
    * The word separator
    * @var string
    * @access private
    */
   var $_sep = ' ';

    /**
    * The currency names (based on the below links,
    * informations from central bank websites and on encyclopedias)
    *
    * @var array
    * @link http://30-03-67.dreamstation.com/currency_alfa.htm World Currency Information
    * @link http://www.jhall.demon.co.uk/currency/by_abbrev.html World currencies
    * @link http://www.shoestring.co.kr/world/p.visa/change.htm Currency names in English
    * @access private
    */
   var $_currency_names = array(
     'ALL' => array(array('lek'), array('qindarka')),
     'AUD' => array(array('Australian dollar'), array('cent')),
     'BAM' => array(array('convertible marka'), array('fenig')),
     'BGN' => array(array('lev'), array('stotinka')),
     'BRL' => array(array('real'), array('centavos')),
     'BYR' => array(array('Belarussian rouble'), array('kopiejka')),
     'CAD' => array(array('Canadian dollar'), array('cent')),
     'CHF' => array(array('Swiss franc'), array('rapp')),
     'CYP' => array(array('Cypriot pound'), array('cent')),
     'CZK' => array(array('Czech koruna'), array('halerz')),
     'DKK' => array(array('Danish krone'), array('ore')),
     'EEK' => array(array('kroon'), array('senti')),
     'EUR' => array(array('euro'), array('cent')),
     'GBP' => array(array('pound', 'pounds'), array('pence', 'pence')),
     'HKD' => array(array('Hong Kong dollar'), array('cent')),
     'HRK' => array(array('Croatian kuna'), array('lipa')),
     'HUF' => array(array('forint'), array('filler')),
     'ILS' => array(array('new sheqel','new sheqels'), array('agora','agorot')),
     'ISK' => array(array('Icelandic króna'), array('aurar')),
     'JPY' => array(array('yen'), array('sen')),
     'LTL' => array(array('litas'), array('cent')),
     'LVL' => array(array('lat'), array('sentim')),
     'MKD' => array(array('Macedonian dinar'), array('deni')),
     'MTL' => array(array('Maltese lira'), array('centym')),
     'NOK' => array(array('Norwegian krone'), array('oere')),
     'PLN' => array(array('zloty', 'zlotys'), array('grosz')),
     'ROL' => array(array('Romanian leu'), array('bani')),
     'RUB' => array(array('Russian Federation rouble'), array('kopiejka')),
     'SEK' => array(array('Swedish krona'), array('oere')),
     'SIT' => array(array('Tolar'), array('stotinia')),
     'SKK' => array(array('Slovak koruna'), array()),
     'TRL' => array(array('lira'), array('kuruþ')),
     'UAH' => array(array('hryvna'), array('cent')),
     'USD' => array(array('dollar'), array('cent')),
     'YUM' => array(array('dinars'), array('para')),
     'ZAR' => array(array('rand'), array('cent'))
   );


   /**
    * The default currency name
    * @var string
    * @access public
    */
   var $def_currency = 'LTL';

   // }}}
   // {{{ _toWords()

   /**
    * Converts a number to its word representation
    * in Lithuanian language
    *
    * @param integer $num       An integer between -infinity and infinity inclusive :)
    *                           that need to be converted to words
    * @param integer $power     The power of ten for the rest of the number to the right.
    *                           Optional, defaults to 0.
    * @param integer $powsuffix The power name to be added to the end of the return string.
    *                            Used internally. Optional, defaults to ''.
    *
    * @return string  The corresponding word representation
    *
    * @access protected
    * @author Laurynas Butkus <[email protected]>
    * @since  Numbers_Words 0.16.3
    */
   function _toWords($num, $power = 0, $powsuffix = '')
   {
       $ret = '';

       // add a minus sign
       if (substr($num, 0, 1) == '-') {
           $ret = $this->_sep . $this->_minus;
           $num = substr($num, 1);
       }

       // strip excessive zero signs and spaces
       $num = trim($num);
       $num = preg_replace('/^0+/', '', $num);

       if (strlen($num) > 3) {
           $maxp = strlen($num)-1;
           $curp = $maxp;
           for ($p = $maxp; $p > 0; --$p) { // power

               // check for highest power
               if (isset($this->_exponent[$p])) {
                   // send substr from $curp to $p
                   $snum = substr($num, $maxp - $curp, $curp - $p + 1);
                   $snum = preg_replace('/^0+/', '', $snum);
                   if ($snum !== '') {
                       $cursuffix = $this->_exponent[$power][count($this->_exponent[$power])-1];
                       if ($powsuffix != '') {
                           $cursuffix .= $this->_sep . $powsuffix;
                       }

                       $ret .= $this->_toWords($snum, $p, $cursuffix);
                   }
                   $curp = $p - 1;
                   continue;
               }
           }
           $num = substr($num, $maxp - $curp, $curp - $p + 1);
           if ($num == 0) {
               return $ret;
           }
       } elseif ($num == 0 || $num == '') {
           return $this->_sep . $this->_digits[0];
       }

       $h = $t = $d = 0;

       switch(strlen($num)) {
       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;
       }

       if ( $h > 1 ) {
           $ret .= $this->_sep . $this->_digits[$h] . $this->_sep . 'šimtai';
       } elseif ( $h ) {
           $ret .= $this->_sep . 'šimtas';
       }

       // ten, twenty etc.
       switch ($t) {
       case 9:
           $ret .= $this->_sep . 'devyniasdešimt';
           break;

       case 8:
           $ret .= $this->_sep . 'aštuoniasdešimt';
           break;

       case 7:
           $ret .= $this->_sep . 'septyniasdešimt';
           break;

       case 6:
           $ret .= $this->_sep . 'šešiasdešimt';
           break;

       case 5:
           $ret .= $this->_sep . 'penkiasdešimt';
           break;

       case 4:
           $ret .= $this->_sep . 'keturiasdešimt';
           break;

       case 3:
           $ret .= $this->_sep . 'trisdešimt';
           break;

       case 2:
           $ret .= $this->_sep . 'dvidešimt';
           break;

       case 1:
           switch ($d) {
           case 0:
               $ret .= $this->_sep . 'dešimt';
               break;

           case 1:
               $ret .= $this->_sep . 'vienuolika';
               break;

           case 2:
               $ret .= $this->_sep . 'dvylika';
               break;

           case 3:
               $ret .= $this->_sep . 'trylika';
               break;

           case 4:
               $ret .= $this->_sep . 'keturiolika';
               break;

           case 5:
               $ret .= $this->_sep . 'penkiolika';
               break;

           case 6:
               $ret .= $this->_sep . 'šešiolika';
               break;

           case 7:
               $ret .= $this->_sep . 'septyniolika';
               break;

           case 8:
               $ret .= $this->_sep . 'aštuoniolika';
               break;

           case 9:
               $ret .= $this->_sep . 'devyniolika';
               break;

           }
           break;
       }

       // add digits only in <0>,<1,9> and <21,inf>
       if ($t != 1 && $d > 0) {
           if ( $d > 1 || !$power || $t ) {
               $ret .= $this->_sep . $this->_digits[$d];
           }
       }

       if ($power > 0) {
           if (isset($this->_exponent[$power])) {
               $lev = $this->_exponent[$power];
           }

           if (!isset($lev) || !is_array($lev)) {
               return null;
           }

           //echo " $t $d  <br>";

           if ($t == 1 || ($t > 0 && $d == 0 )) {
               $ret .= $this->_sep . $lev[2];
           } elseif ( $d > 1 ) {
               $ret .= $this->_sep . $lev[1];
           } else {
               $ret .= $this->_sep . $lev[0];
           }
       }

       if ($powsuffix != '') {
           $ret .= $this->_sep . $powsuffix;
       }

       return $ret;
   }
   // }}}

       // {{{ toCurrencyWords()

   /**
    * Converts a currency value to its word representation
    * (with monetary units) in English language
    *
    * @param integer $int_curr         An international currency symbol
    *                                  as defined by the ISO 4217 standard (three characters)
    * @param integer $decimal          A money total amount without fraction part (e.g. amount of dollars)
    * @param integer $fraction         Fractional part of the money amount (e.g. amount of cents)
    *                                  Optional. Defaults to false.
    * @param integer $convert_fraction Convert fraction to words (left as numeric if set to false).
    *                                  Optional. Defaults to true.
    *
    * @return string  The corresponding word representation for the currency
    *
    * @access public
    * @author Piotr Klaban <[email protected]>
    * @since  Numbers_Words 0.4
    */
   function toCurrencyWords($int_curr, $decimal, $fraction = false, $convert_fraction = false)
   {
       $int_curr = strtoupper($int_curr);
       if (!isset($this->_currency_names[$int_curr])) {
           $int_curr = $this->def_currency;
       }
       $curr_names = $this->_currency_names[$int_curr];

       $ret = trim($this->_toWords($decimal));
       $lev = ($decimal == 1) ? 0 : 1;
       if ($lev > 0) {
           if (count($curr_names[0]) > 1) {
               $ret .= $this->_sep . $curr_names[0][$lev];
           } else {
               $ret .= $this->_sep . $curr_names[0][0] . 's';
           }
       } else {
           $ret .= $this->_sep . $curr_names[0][0];
       }

       if ($fraction !== false) {
           if ($convert_fraction) {
               $ret .= $this->_sep . trim($this->_toWords($fraction));
           } else {
               $ret .= $this->_sep . $fraction;
           }
           $lev = ($fraction == 1) ? 0 : 1;
           if ($lev > 0) {
               if (count($curr_names[1]) > 1) {
                   $ret .= $this->_sep . $curr_names[1][$lev];
               } else {
                   $ret .= $this->_sep . $curr_names[1][0] . 's';
               }
           } else {
               $ret .= $this->_sep . $curr_names[1][0];
           }
       }
       return $ret;
   }
   // }}}
}

Nuoroda į pranešimą
Dalintis kituose puslapiuose

Prisijunkite prie diskusijos

Jūs galite rašyti dabar, o registruotis vėliau. Jeigu turite paskyrą, prisijunkite dabar, kad rašytumėte iš savo paskyros.

Svečias
Parašykite atsakymą...

×   Įdėta kaip raiškusis tekstas.   Atkurti formatavimą

  Only 75 emoji are allowed.

×   Nuorodos turinys įdėtas automatiškai.   Rodyti kaip įprastą nuorodą

×   Jūsų anksčiau įrašytas turinys buvo atkurtas.   Išvalyti redaktorių

×   You cannot paste images directly. Upload or insert images from URL.

Įkraunama...
  • Dabar naršo   0 narių

    Nei vienas registruotas narys šiuo metu nežiūri šio puslapio.

  • Prisijunk prie bendruomenės dabar!

    Uždarbis.lt nariai domisi verslo, IT ir asmeninio tobulėjimo temomis, kartu sprendžia problemas, dalinasi žiniomis ir idėjomis, sutinka būsimus verslo partnerius ir dalyvauja gyvuose susitikimuose.

    Užsiregistruok dabar ir galėsi:

    ✔️ Dalyvauti diskusijose;

    ✔️ Kurti naujas temas;

    ✔️ Rašyti atsakymus;

    ✔️ Vertinti kitų žmonių pranešimus;

    ✔️ Susisiekti su bet kuriuo nariu asmeniškai;

    ✔️ Naudotis tamsia dizaino versija;

    ir dar daugiau.

    Registracija trunka ~30 sek. ir yra visiškai nemokama.

  • Naujausios temos

  • Karštos temos

×
×
  • Pasirinkite naujai kuriamo turinio tipą...