Page 1 of 2 1 2 LastLast
Results 1 to 15 of 27

Thread: Change number to text

  1. #1
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    187

    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.

  2. #2
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    187
    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>

  3. #3
    Join Date
    Feb 2004
    Location
    Klang Bandar Diraja
    Posts
    160
    Rep Power
    191
    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.

  4. #4
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    187
    cannot solve with just change the words how about :

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

    that is the problemm

  5. #5
    Join Date
    Jul 2001
    Location
    ttdi
    Posts
    130
    Rep Power
    221
    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.

  6. #6
    Join Date
    May 2002
    Location
    Klate
    Posts
    91
    Rep Power
    210
    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);


  7. #7
    Join Date
    Nov 2001
    Location
    Johor
    Posts
    772
    Rep Power
    230
    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

  8. #8
    Join Date
    May 2002
    Location
    Klate
    Posts
    91
    Rep Power
    210
    huhu maybe yes maybe not, who knows

  9. #9
    Join Date
    Feb 2004
    Location
    Klang Bandar Diraja
    Posts
    160
    Rep Power
    191

    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.

  10. #10
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    187
    still dun understand..how to echo the result?

  11. #11
    Join Date
    Feb 2004
    Location
    Klang Bandar Diraja
    Posts
    160
    Rep Power
    191
    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.

  12. #12
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    187
    thank you nurulmajdi...

    how about if got cent?
    the code didn't workin for cent.

  13. #13
    Join Date
    May 2002
    Location
    Klate
    Posts
    91
    Rep Power
    210
    cent? camne tu? cuba terangkan sket..
    macam bagi nilai 123.60 ke?

  14. #14
    Join Date
    Mar 2004
    Location
    malaysia
    Posts
    96
    Rep Power
    187
    yup macam gitu la 123.50 ke 896.50

  15. #15
    Join Date
    May 2002
    Location
    Klate
    Posts
    91
    Rep Power
    210
    try this function with previous one

    PHP Code:
    function money2txt($money)
    {
    $money=explode(".",$money);
    $money[0]=num2txt($money[0]);
    $money[1]=num2txt($money[1]);
    return 
    "$money[0] ringgit and $money[1] cent";


Page 1 of 2 1 2 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Know Your Personal Identification Number
    By emoney1111 in forum E-Commerce
    Replies: 0
    Last Post: 25-09-2007, 08:37 PM
  2. Tax number , Social Security number for affliate programs
    By cyrick in forum Revenue and Monetization
    Replies: 6
    Last Post: 28-03-2006, 12:33 AM
  3. Your fax-to-email number
    By uniceed2005 in forum Other Webmaster-related Services and Promotion
    Replies: 0
    Last Post: 13-11-2005, 11:49 PM
  4. Floating number
    By koisempoi in forum Website Programming
    Replies: 2
    Last Post: 12-08-2005, 03:34 PM
  5. Audible / Turing Number
    By naero in forum Website Programming
    Replies: 5
    Last Post: 02-07-2005, 04:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search Engine Optimization by vBSEO 3.5.0 RC1 PL1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37