Fordnox

Life is about trust

Subscribe to Fordnox
Technorati
del.icio.us
August-1-08

Numbers to Words

posted by Andrius

The best solution for this problem is Pear package, but if you don’t like it, you can use this PHP class for converting to Lithuanian language:

Gal = "";
		$c = $this->Tukst($a, "", "", "");
		$skaicius = intval($skaicius / 1000);
		$a = $skaicius;
		If ($a % 1000 > 0) {
			$c = $this->Tukst($a, "čių", "tis", "čiai") . " tūkstan" . $this->Gal . " " . $c;
		}
		$skaicius = intval($skaicius / 1000);
		$a = $skaicius;
		If ($a % 1000 > 0) {
			$c = $this->Tukst($a, "ų", "as", "ai") . " milijon" . $this->Gal . " " . $c;
		}
		If ($formatas == 0) {
			If ($sk > 0) {
				$c = trim($c) . " Lt ";
			}
			Else {
				$c = "nulis Lt ";
			}
			$tmp = $this->Str((1 + $sk));
			//echo "$tmp
\n";
			$tmp = $tmp*100;
			//echo "$tmp
\n";
			////$tmp = $tmp%10000;
			//echo "$tmp
\n";
			$tmp = trim($tmp);
			//echo "$tmp
\n";
			//$tmp = mid($tmp, 1, 2);
			$tmp = substr($tmp, -2);
			//echo "$tmp
\n";

			//$c = $c . mid(trim(Str((1 + $sk) * 100 % 1000)), 1, 2) . " ct";
			$c = $c . $tmp . " ct";
		}
		If ($formatas == 1) {
			If (Intval($sk) == 0) {
				$c = "nulis";
			}
			$c = $c . " vienet" . $this->GG(Intval($sk));
		}
		$c = $this->UPPER_LT($this->Mid($c, 0, 1)) . $this->Mid($c, 1, 254);
		return $c;
	}

	private Function Tukst($A , $G1, $G2, $G3)
	{
		$C = "";
		$this->Gal = "";
		If ($A == 0) {
			//return $C;
		}
		$B = $A % 10;
		If ($B == 0) {
			$this->Gal = $G1;
		}
		If ($B == 1) {
			$this->Gal = $G2;
		}
		If ($B > 1) {
			$this->Gal = $G3;
		}
		switch ($B) {
			Case 1:
				$C = "vienas";
				break;
				Case 2:
					$C = "du";
					break;
					Case 3:
						$C = "trys";
						break;
						Case 4:
							$C = "keturi";
							break;
							Case 5:
								$C = "penki";
								break;
								Case 6:
									$C = "šeši";
									break;
									Case 7:
										$C = "septyni";
										break;
										Case 8:
											$C = "aštuoni";
											break;
											Case 9:
												$C = "devyni";
												break;
		}
		$B1 = $B;
		$A = Intval($A / 10);
		$B = $A % 10;
		If ($B == 1) {
			$this->Gal = $G1;
			switch ($B1) {
				Case 0:
					$C = "dešimt";
					break;
					Case 1:
						$C = "vienuolika";
						break;
						Case 2:
							$C = "dvylika";
							break;
							Case 3:
								$C = "trylika";
								break;
								Case 4:
									$C = "keturiolika";
									break;
									Case 5:
										$C = "penkiolika";
										break;
										Case 6:
											$C = "šešiolika";
											break;
											Case 7:
												$C = "septyniolika";
												break;
												Case 8:
													$C = "aštuoniolika";
													break;
													Case 9:
														$C = "devyniolika";
														break;
			}
		}
		switch ($B) {
			Case 2:
				$C = "dvidešimt " . $C;
				break;
				Case 3:
					$C = "trisdešimt " . $C;
					break;
					Case 4:
						$C = "keturiasdešimt " . $C;
						break;
						Case 5:
							$C = "penkiasdešimt " . $C;
							break;
							Case 6:
								$C = "šešiasdešimt " . $C;
								break;
								Case 7:
									$C = "septyniasdešimt " . $C;
									break;
									Case 8:
										$C = "aštuoniasdešimt " . $C;
										break;
										Case 9:
											$C = "devyniasdešimt " . $C;
											break;
		}

		$A = Intval($A / 10);
		$B = $A % 10;
		switch ($B) {
			Case 1:
				$C = "vienas šimtas " . $C;
				break;
				Case 2:
					$C = "du šimtai " . $C;
					break;
					Case 3:
						$C = "trys šimtai " . $C;
						break;
						Case 4:
							$C = "keturi šimtai " . $C;
							break;
							Case 5:
								$C = "penki šimtai " . $C;
								break;
								Case 6:
									$C = "šeši šimtai " . $C;
									break;
									Case 7:
										$C = "septyni šimtai " . $C;
										break;
										Case 8:
											$C = "aštuoni šimtai " . $C;
											break;
											Case 9:
												$C = "devyni šimtai " . $C;
												break;
		}
		return $C;
	}

	private function GG($X)
	{
		If (Intval($X / 10) % 10 != 1) {
			switch ($X % 10)
			{
				Case 0:
					return "ų";
					break;
					Case 1:
						return "as";
						break;
					default:
						return "ai";
			}
		}
		Else {
			return "ų";
		}
		return "";
	}

	private function UPPER_LT($s)
	{
		return strtoupper($s);
	}

	private function Mid($s, $from, $len) {
		return substr($s, $from, $len);
	}

	private function Str($i)
	{
		return $i;
	}
}
?>

Add A Comment