Numbers to words

I want convert a number amount to words
Can anyone heplme?

ScriptCase does not have a library to do this. But I found this code from [B]Hugh Bothwell /B that can spell numbers up to nonillions:

// Hugh Bothwell hugh_bothwell@hotmail.com 
// August 31 2001
// Number-to-word converter

$ones = array
(
   "",
   " one",
   " two",
   " three",
   " four",
   " five",
   " six",
   " seven",
   " eight",
   " nine",
   " ten",
   " eleven",
   " twelve",
   " thirteen",
   " fourteen",
   " fifteen",
   " sixteen",
   " seventeen",
   " eighteen",
   " nineteen"
);

$tens = array
(
   "",
   "",
   " twenty",
   " thirty",
   " forty",
   " fifty",
   " sixty",
   " seventy",
   " eighty",
   " ninety"
);

$triplets = array
(
   "",
   " thousand",
   " million",
   " billion",
   " trillion",
   " quadrillion",
   " quintillion",
   " sextillion",
   " septillion",
   " octillion",
   " nonillion"
);

// recursive fn, converts three digits per pass
function convertTri($num, $tri) 
{
   global $ones, $tens, $triplets;

// chunk the number, ...rxyy
   $r = (int) ($num / 1000);
   $x = ($num / 100) % 10;
   $y = $num % 100;

// init the output string
   $str = "";

// do hundreds
   if ($x > 0)
      $str = $ones[$x] . " hundred";

// do ones and tens
   if ($y < 20)
      $str .= $ones[$y];
   else
      $str .= $tens[(int) ($y / 10)] . $ones[$y % 10];

// add triplet modifier only if there
// is some output to be modified...
   if ($str != "")
      $str .= $triplets[$tri];

// continue recursing?
   if ($r > 0)
      return convertTri($r, $tri+1).$str;
   else
      return $str;
}

// returns the number as an anglicized string
function convertNum($num) 
{
   $num = (int) $num; // make sure it's an integer

   if ($num < 0)
      return "negative".convertTri(-$num, 0);

   if ($num == 0)
      return "zero";

   return convertTri($num, 0);
}

More info will be found here: http://marc.info/?l=php-general&m=99928281523866&w=2

Thank You Henriqueb.

how to apply it in the report pdf

Import the code on an internal library for example, and use the function convertNum(). Then, print on screeen the value converted

Can anyone please help me on how to implement this on a pdf report in SC8. I imported the code on an internal library, called the it in my application and I am stuck. I have tried to use the function convertNum() in an OnRecord event but to no avail. Please help I have been struggling with this for weeks. thank you

I have found a way out. Thank alot.

Just so you guys know… there is a way in php already to spell out a number into letters


<?php
$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $f->format(123456);

?>


So there’s no need to create addditional functions.

ROFL, I was studying hundreds of lines of code to understand how actually it is happening. Thanks for this time-saving technique man.

It simply works for me.

Hello Zubair:

Glad you found it helpful. Keep on styding anyways that’s never a waste.

Regards

Very Good. It?s easy to use.:rolleyes: