1.

Solve : Help pls..Numbers into words?

Answer»

Hello
  I would like to know How do I change Numbers into words,  I have a programming code that does this but I can't get it to work so I want to change it in to a java code instead so it can work on INTERNET explorer page.

Any help would be great thanks
Carl

Please don't post the same question more than once. I deleted the other topic.Java or Javascript?Sorry about that Allan

Hi Kpac I don't mind which ever one is easier to do.No, I meant which one were you talking about?
Quote

I want to change it in to a java code instead so it can work on internet explorer page.

Also, post the code you have at the moment.Ok Well I'm new to coding so I guess javascript

My Programming Code Is......

/*
 *  Function:    number_to_words
 *  Description:  recursive numerics to words function
 *  Converts a given integer (in range [0..1T-1], inclusive) into
 *  alphabetical format ("one", "two", etc.)
 *  int
 *  return string
 */

function number_to_words($number)
{
    if (($number < 0) || ($number > 999999999))
    {
       throw new Exception("Number is out of range");
    }

    $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 */

    $result = "";

    if ($Gn)
    {  $result .= number_to_words($Gn) . " Million";  }

    if ($kn)
    {  $result .= (empty($result) ? "" : " ") . number_to_words($kn) . " Thousand"; }

    if ($Hn)
    {  $result .= (empty($result) ? "" : " ") . number_to_words($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($result))
       {  $result .= " and ";
       }

       if ($Dn < 2)
       {  $result .= $ones[$Dn * 10 + $n];
       }
       ELSE
       {  $result .= $tens[$Dn];
          if ($n)
          {  $result .= "-" . $ones[$n];
          }
       }
    }

    if (empty($result))
    {  $result = "zero"; }

    return $result;
}
That's PHP. All you do is called the number_to_words function, i.e.

Code: [Select]<?php
  number_to_words(560); 
?>...should return "five hundred and sixty".yea but What I mean Is,
  I've opened up text Document and TYPED in the html,head,script,body & html the Basic stuff and I've placed it in between the Placed it here and when I open It it doesn't do anything just shows me the code.

I don't know anything about php. Quote
I've opened up text Document and typed in the html,head,script,body & html the Basic stuff and I've placed it in between the <script>Placed it here</script> and when I open It it doesn't do anything just shows me the code.
That's the problem.

Here: http://javascript.about.com/library/bltoword.htm
More: Goooooogleyea I was hoping to change 1-24 into words that I type in ie:- 1 = pasta 2 = chips 3 = pie 4 = soup 5 = shreddies etc etc

Say I type 24 words and it changes all my numbers into those words To be honest, all the hard work has been done for you.  Converting the code from PHP to javascript is not that difficult.

Do you want someone to do the whole exercise for you?  You might be interested in trying http://www.vworker.com/ - there are coders in India that would do something like this for $5 or so.


Discussion

No Comment Found