Go Back   Webmaster Malaysia Forum » Website Design & Development » Website Programming

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 19-05-2004, 04:39 PM
lina's Avatar
Novice Webmaster
 
Join Date: Mar 2004
Location: malaysia
Posts: 96
Rep Power: 58
lina is on a distinguished road
Send a message via Yahoo to lina
Change number to text

I need an expert to solve this problem. I have the solution for bahasa malaysia but i need for BI which i still adjusting the coding.

E.g.:

150 change to one hundred fifty

2300 change to two thousand three hundred

Thank you in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 19-05-2004, 04:43 PM
lina's Avatar
Novice Webmaster
 
Join Date: Mar 2004
Location: malaysia
Posts: 96
Rep Power: 58
lina is on a distinguished road
Send a message via Yahoo to lina
Here is progress coding :

filename : index.php

<?php

//TEXT NUM declaration
$numArray[0]="";
$numArray[1]="One";
$numArray[2]="Two";
$numArray[3]="Three";
$numArray[4]="Four";
$numArray[5]="Five";
$numArray[6]="Six";
$numArray[7]="Seven";
$numArray[8]="Eight";
$numArray[9]="Nine";

$pointArray[0]="";
$pointArray[1]="ty";
$pointArray[2]="Hundred";
$pointArray[3]="Thousand";

//input
$input=$txtNum;

//split the decimal place
$stat=0;
$in[0]="";
$in[1]="";
for($a=0;$a<strlen($input);$a++){
if ($stat==0){
if($input{$a} != ".") $in[0].=$input{$a};
else $stat=1;
}
else{
$in[1].=$input{$a};
}
}
//calculate left value (before decimal)
$leftVal=leftVal($in[0]);

//calculate right value (after decimal) only accept 2 decimal place
$trimmedVal=substr($in[1],0,2);
$decimalText=rightVal($trimmedVal);

function leftVal($number){
global $numArray;
global $pointArray;

$numtext="";

$len=strlen($number);
$temp[]="";

//split left number by 3 decimal place grouping 1234567 -> {1},{234},{567}
$b=0;
$x=$len-3;
$y=3;
for ($a=$len;$a>0;$a=$a-3){
if($x<0)
{
$x=0;
$y=$a;
}
$temp[$b]=substr($number,$x,$y);
$x=$x-3;

$b=$b+1;
}

//calculate left value
for($a=0;$a<sizeof($temp);$a++){

$tText="";
for($b=0;$b<strlen($temp[$a]);$b++){
if(strlen($temp[$a])==3 && $b==1){
if($temp[$a]{1}==1){
if($temp[$a]{2} > 1){
$tText.=$numArray[($temp[$a]{$b+1})]. " belas";
$b=strlen($temp[$a]);
}
else if($temp[$a]{2} == 0){
$tText.="Sepuluh";
$b=strlen($temp[$a]);
}
else if($temp[$a]{2} == 1){
$tText.="Sebelas";
$b=strlen($temp[$a]);
}
}
else{
$tText.=$numArray[($temp[$a]{$b})]. " ";
if($temp[$a]{$b} != 0) $tText.=$pointArray[strlen($temp[$a])-$b-1] ." ";
}
}
else if(strlen($temp[$a])==2 && $b==0){
if($temp[$a]{0}==1){
if($temp[$a]{1} == 0){
$tText.="Ten";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 1){
$tText.="Eleven";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 2){
$tText.="Twelve";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 3){
$tText.="Thirteen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 4){
$tText.="Fourteen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 5){
$tText.="Fifteen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 6){
$tText.="Sixteen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 7){
$tText.="Seventeen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 8){
$tText.="Eighteen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 9){
$tText.="Nineteen";
$b=strlen($temp[$a]);
}
}
else{
$tText.=$numArray[($temp[$a]{$b})]. " ";
if($temp[$a]{$b} != 0) $tText.=$pointArray[strlen($temp[$a])-$b-1] ." ";
}
}
else{
$tText.=$numArray[($temp[$a]{$b})]. " ";
if($temp[$a]{$b} != 0) $tText.=$pointArray[strlen($temp[$a])-$b-1] ." ";
}
}

if($a>0){
if(trim($tText) != "") $numtext=$tText ." ".$pointArray[$a+2] . " " . $numtext;
}
else{
$numtext=$tText . $numtext;
}
}
return $numtext;
}

function rightVal($decimal){
global $numArray;
global $pointArray;
$tText="";
for($b=0;$b<strlen($decimal);$b++){
if($b==0){
if($decimal{1} == 0){
$tText.="Ten";
$b=strlen($decimal);
}
else if($decimal{1} == 1){
$tText.="Eleven";
$b=strlen($decimal);
}
else if($decimal{1} == 2){
$tText.="Twelve";
$b=strlen($decimal);
}
else if($temp[$a]{1} == 3){
$tText.="Thirteen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 4){
$tText.="Fourteen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 5){
$tText.="Fifteen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 6){
$tText.="Sixteen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 7){
$tText.="Seventeen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 8){
$tText.="Eighteen";
$b=strlen($temp[$a]);
}
else if($temp[$a]{1} == 9){
$tText.="Nineteen";
$b=strlen($temp[$a]);
}
else{
$tText.=$numArray[($decimal{$b})]. " ";
if($decimal{$b} != 0) $tText.=$pointArray[strlen($decimal)-$b-1] ." ";
}
}
else{
$tText.=$numArray[($decimal{$b})]. " ";
if($decimal{$b} != 0) $tText.=$pointArray[strlen($decimal)-$b-1] ." ";
}

}
return $tText;
}

print($input."<br>");
print($leftVal. " Ringgit DAN ".$decimalText."Sen")

?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body><form action=index.php name=form1>
Number :
<input type=text name=txtNum value="<?php echo $input?>"><input type=submit value=ok></form>

</body>
</html>
__________________
liNa
http://2lina.blogspot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 19-05-2004, 05:15 PM
nurulmajdi's Avatar
Inspired Webmaster
 
Join Date: Feb 2004
Location: Klang Bandar Diraja
Posts: 160
Rep Power: 62
nurulmajdi is on a distinguished road
Send a message via Yahoo to nurulmajdi
language prob?? i don't understand.. if the code can applied to malay then just change the words into english words.. huurmm.... explain a bit more about your prob.. can't you?
__________________
To follow the path:
Look to the master,
Follow the master,
Walk with the master,
See through the master,
Become the master.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 19-05-2004, 05:22 PM
lina's Avatar
Novice Webmaster
 
Join Date: Mar 2004
Location: malaysia
Posts: 96
Rep Power: 58
lina is on a distinguished road
Send a message via Yahoo to lina
cannot solve with just change the words how about :

sepuluh - ten
enam puluh - six ten(can not be !!)

that is the problemm
__________________
liNa
http://2lina.blogspot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 21-05-2004, 11:01 AM
zaimlah's Avatar
Inspired Webmaster
 
Join Date: Jul 2001
Location: ttdi
Posts: 129
Rep Power: 92
zaimlah is on a distinguished road
ah, interesting!

i cannot solve the problem immediately now, but i will try it out... quite a challenge.

just to mention, you can format numbers (e.g. changing 1234567 => 1,234,567) by using the number_format function.
__________________
blog:zaim_bakar_blog | biz:box
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 22-05-2004, 07:24 AM
hafizuddin's Avatar
Novice Webmaster
 
Join Date: May 2002
Location: Klate
Posts: 91
Rep Power: 81
hafizuddin is on a distinguished road
maybe u can try my code...

PHP Code:
function num2txt($i)
{

function 
one29($i)
{
$list=explode(",",",one,two,three,four,five,six,seven,eight,nine,ten");
return 
$list[$i];
}

function 
ten219($i)
{
$list=explode(",","ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen");
return 
$list[$i];
}

function 
twenty299($i)
{
$list=explode(",",",,twenty,thirty,fourty,fifty,sixty,seventy,eighty,ninety");
return 
$list[$i];
}

function 
check1299($i)
{
$i=intval($i);
if (
$i<=9) return one29($i);
if (
$i<=19) return ten219($i-10);
if (
$i<=99)
{
$a=twenty299(substr($i,0,1));
$b=one29(substr($i,1,1));
return 
"$a $b";
}
}

function 
hundreds($i)
{
$a=one29(substr($i,0,1))." hundred";
$b=check1299(substr($i,1));
return 
"$a $b";
}

function 
thousands($i)
{
if (
strlen($i)==4) { $a=check1299(substr($i,0,1))." thousand"$b=hundreds(substr($i,1)); }
if (
strlen($i)==5) { $a=check1299(substr($i,0,2))." thousand"$b=hundreds(substr($i,2)); }
if (
strlen($i)==6) { $a=hundreds(substr($i,0,3))." thousand"$b=hundreds(substr($i,3)); }
return 
"$a $b";
}

function 
millions($i)
{
if (
strlen($i)==7) { $a=check1299(substr($i,0,1))." million"$b=thousands(substr($i,1)); }
if (
strlen($i)==8) { $a=check1299(substr($i,0,2))." million"$b=thousands(substr($i,2)); }
if (
strlen($i)==9) { $a=hundreds(substr($i,0,3))." million"$b=thousands(substr($i,3)); }
return 
"$a $b";
}

function 
billions($i)
{
if (
strlen($i)==10) { $a=check1299(substr($i,0,1))." billion"$b=millions(substr($i,1)); }
if (
strlen($i)==11) { $a=check1299(substr($i,0,2))." billion"$b=millions(substr($i,2)); }
if (
strlen($i)==12) { $a=hundreds(substr($i,0,3))." billion"$b=millions(substr($i,3)); }
return 
"$a $b";
}

if (
$i<99) return check1299($i);
if (
$i<=999) return hundreds($i);
if (
$i<=999999) return thousands($i);
if (
$i<=999999999) return millions($i);
if (
$i<=999999999999) return billions($i);

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 22-05-2004, 11:06 AM
hymns's Avatar
Senior Webmaster
 
Join Date: Nov 2001
Location: Johor
Posts: 769
Rep Power: 101
hymns is on a distinguished road
Send a message via ICQ to hymns Send a message via Yahoo to hymns
problem solve...

*did i see this code b4?*
__________________
I hate when:

vBulletin Message:
Sorry! The administrator has specified that users can only post one message every 60 seconds
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 22-05-2004, 02:55 PM
hafizuddin's Avatar
Novice Webmaster
 
Join Date: May 2002
Location: Klate
Posts: 91
Rep Power: 81
hafizuddin is on a distinguished road
huhu maybe yes maybe not, who knows
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 24-05-2004, 10:11 AM
nurulmajdi's Avatar
Inspired Webmaster
 
Join Date: Feb 2004
Location: Klang Bandar Diraja
Posts: 160
Rep Power: 62
nurulmajdi is on a distinguished road
Send a message via Yahoo to nurulmajdi
wwaa....

heeh.. aku yg ajar tuu...
__________________
To follow the path:
Look to the master,
Follow the master,
Walk with the master,
See through the master,
Become the master.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 24-05-2004, 10:13 AM
lina's Avatar
Novice Webmaster
 
Join Date: Mar 2004
Location: malaysia
Posts: 96
Rep Power: 58
lina is on a distinguished road
Send a message via Yahoo to lina
still dun understand..how to echo the result?
__________________
liNa
http://2lina.blogspot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 24-05-2004, 10:20 AM
nurulmajdi's Avatar
Inspired Webmaster
 
Join Date: Feb 2004
Location: Klang Bandar Diraja
Posts: 160
Rep Power: 62
nurulmajdi is on a distinguished road
Send a message via Yahoo to nurulmajdi
cuba try call the function num2txt($anynumber);
let say

num2txt(26);

and then see what the result...
__________________
To follow the path:
Look to the master,
Follow the master,
Walk with the master,
See through the master,
Become the master.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 24-05-2004, 10:25 AM
lina's Avatar
Novice Webmaster
 
Join Date: Mar 2004
Location: malaysia
Posts: 96
Rep Power: 58
lina is on a distinguished road
Send a message via Yahoo to lina
thank you nurulmajdi...

how about if got cent?
the code didn't workin for cent.
__________________
liNa
http://2lina.blogspot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 24-05-2004, 11:36 AM
hafizuddin's Avatar
Novice Webmaster
 
Join Date: May 2002
Location: Klate
Posts: 91
Rep Power: 81
hafizuddin is on a distinguished road
cent? camne tu? cuba terangkan sket..
macam bagi nilai 123.60 ke?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 24-05-2004, 11:39 AM
lina's Avatar
Novice Webmaster
 
Join Date: Mar 2004
Location: malaysia
Posts: 96
Rep Power: 58
lina is on a distinguished road
Send a message via Yahoo to lina
yup macam gitu la 123.50 ke 896.50
__________________
liNa
http://2lina.blogspot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (