ใครแก้ได้ช่วยหนูด้วยค่ะ ( เรื่อง Convert Number ) TWENTY EIGHT THOUSAND SEVEN HUNDRED EIGHTY FIVE BAHT AND SIXTY EIGHT SATANG
<?php
/*
** Function: convert_number
** Arguments: int
** Returns: string
** Description:
** Converts a given integer (in range [0..1T-1], inclusive) into
** alphabetical format ("one", "two", etc.).
*/
function convert_number($number)
{
if (($number < 0) || ($number > 999999999))
{
return "$number";
}
$Gn = floor($number / 1000000); /* Millions (giga) */
$number -= $Gn * 1000000;
$kn = floor($number / 1000); /* Thousands (kilo) */
$number -= $kn * 1000;
$Hn = floor($number / 100); /* Hundreds (hecto) */
$number -= $Hn * 100;
$Dn = floor($number / 10); /* Tens (deca) */
$n = $number % 10; /* Ones */
$res = "";
if ($Gn)
{
$res .= convert_number($Gn) . " Million";
}
if ($kn)
{
$res .= (empty($res) ? "" : " ") .
convert_number($kn) . " Thousand";
}
if ($Hn)
{
$res .= (empty($res) ? "" : " ") .
convert_number($Hn) . " Hundred";
}
$ones = array("", "One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen",
"Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eightteen",
"Nineteen");
$tens = array("", "", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty",
"Seventy", "Eigthy", "Ninety");
if ($Dn || $n)
{
if (!empty($res))
{
$res .= " and ";
}
if ($Dn < 2)
{
$res .= $ones[$Dn * 10 + $n];
}
else
{
$res .= $tens[$Dn];
if ($n)
{
$res .= "-" . $ones[$n];
}
}
}
if (empty($res))
{
$res = "zero";
}
return $res;
}
$amt = round(28785.68) ;
echo $amt." = ". convert_number($amt);
?>
เมื่อรันแล้วผลลัพท์ได้ = Twenty-Eight Thousand Seven Hundred and Eigthy-Six
ที่จริงต้องเป็น " TWENTY EIGHT THOUSAND SEVEN HUNDRED EIGHTY FIVE BAHT AND SIXTY EIGHT SATANG "
ใครแก้ได้ช่วยด้วยนะคะTag : - - - -
Date :
28 ก.ค. 2551 15:28:49
By :
น้อยหน่า
View :
4099
Reply :
0
Load balance : Server 05