Hi,
I've been googling but havent come across any simple script to convert 100.00 to One Hundred
I dont want to use classes and other complicated stuff. Just a simple code.
I found the following on a site but it doesnt seem to be running the query.
The first part of the code is where my 100.00 gets generated and the 2nd part is what i found on the net.
Can anyone advise a simpler way ? Thanks !
<?
$sqlx= "SELECT Sum(Tax) FROM Contract WHERE `userid` ='$user' ";
$resultx = mysql_query ($sqlx)
or die (mysql_error());
if ($myresult = mysql_result($resultx,0)) // This is the sum of the column Tax.
?>
<?php
$nwords = array( "zero", "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
"nineteen", "twenty", 30 => "thirty", 40 => "forty",
50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty",
90 => "ninety" );
function int_to_words($myresult)
{
global $nwords;
if(!is_numeric($myresult))
{
$w = '#';
}else if(fmod($myresult, 1) != 0)
{
$w = '#';
}else{
if($myresult < 0)
{
$w = 'minus ';
$myresult = -$myresult;
}else{
$w = '';
}
if($myresult < 21)
{
$w .= $nwords[$myresult];
}else if($myresult < 100)
{
$w .= $nwords[10 * floor($myresult/10)];
$r = fmod($myresult, 10);
if($r > 0)
{
$w .= '-'. $nwords[$r];
}
} else if($myresult < 1000)
{
$w .= $nwords[floor($myresult/100)] .' hundred';
$r = fmod($myresult, 100);
if($r > 0)
{
$w .= ' and '. int_to_words($r);
}
} else if($myresult < 1000000)
{
$w .= int_to_words(floor($myresult/1000)) .' thousand';
$r = fmod($myresult, 1000);
if($r > 0)
{
$w .= ' ';
if($r < 100)
{
$w .= 'and ';
}
$w .= int_to_words($r);
}
} else {
$w .= int_to_words(floor($myresult/1000000)) .' million';
$r = fmod($myresult, 1000000);
if($r > 0)
{
$w .= ' ';
if($r < 100)
{
$word .= 'and ';
}
$w .= int_to_words($r);
}
}
}
// return $w;
}
?>
The total cost is
<?php
echo $w ?>