May 2018
SunMonTueWedThuFriSat
  12345
6789101112
13141516171819
20212223242526
2728293031  

Calendar Calendar

Latest topics
» Kabaddi, Kabaddi, Kabaddi, Kabaddi......PHP?
Fri Jul 22, 2011 1:37 pm by shyamsunder

» Thousands of Free PHP Scripts Recommended
Wed May 18, 2011 10:33 am by bizboy12

» PHP form validation problem?
Wed Jan 12, 2011 1:25 pm by simy202

» string wrap
Sat Aug 02, 2008 2:06 pm by scvinodkumar

» retrieving current date rows
Tue Jul 15, 2008 3:25 am by scvinodkumar

» number in words
Tue Apr 29, 2008 3:10 pm by scvinodkumar

» Simple PHP Form Field Generator
Fri Apr 25, 2008 12:28 pm by scvinodkumar

» PHP password generator
Fri Apr 18, 2008 7:24 pm by scvinodkumar

» PHP Script to Extract Email Address from any text
Fri Apr 18, 2008 7:18 pm by scvinodkumar

Search
 
 

Display results as :
 


Rechercher Advanced Search

Affiliates
free forum
 


Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

number in words

Go down

number in words

Post  scvinodkumar on Tue Apr 29, 2008 3:10 pm

<?php
function spellNumberInEnglish ($number) {
$number = strval($number);
if (!ereg("^[0-9]{1,15}$", $number))
return(false);
$ones = array("", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine");
$teens = array("ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen");
$tens = array("", "", "twenty", "thirty", "forty",
"fifty", "sixty", "seventy", "eighty", "ninety");
$majorUnits = array("", "thousand", "million", "billion", "trillion");
$result = "";
$isAnyMajorUnit = false;
$length = strlen($number);
for ($i = 0, $pos = $length - 1; $i < $length; $i++, $pos--) {
if ($number{$i} != '0') {
if ($pos % 3 == 0)
$result .= $ones[$number{$i}] . ' ';
else if ($pos % 3 == 1) {
if ($number{$i} == '1') {
$result .= $teens[$number{$i + 1}] . ' ';
$i++; $pos--;
} else {
$result .= $tens[$number{$i}];
$result .= $number{$i + 1} == '0'? ' ' : '-';
}
} else
$result .= $ones[$number{$i}] . " hundred ";
$isAnyMajorUnit = true;
}
if ($pos % 3 == 0 && $isAnyMajorUnit) {
$result .= $majorUnits[$pos / 3] . ' ';
$isAnyMajorUnit = false;
}
}
trim($result);
if ($result == "") $result = "zero";
return($result);
}

echo spellNumberInEnglish('100');
?>

scvinodkumar
Admin

Posts : 40
Join date : 2008-01-30

View user profile http://solutions.aforumfree.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum