In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] says... > Hi all > How can convert number to letters in PHP? > ( for example 254=two handres and fifty four ) > > Thanks for help
Here's a NumtoWords function in Pascal. I don't have one in PHP...Maybe someone could convert it for us...<bg> (*********************************************************************** NumToWords( <dAmount> ) - Converts a number to its spoken value. Example: NumToWords(234.56) returns "Two Hundred Thirty-Four and 56/100ths' ***********************************************************************) function NumToWords( dAmount: Double ): String; var cString : String; iTemp : LongInt; XX : LongInt; dPow : Double; function NWord( nAmount: Integer ): String; const AWords: array[1..27] of String[9] = ( 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety'); var sTemp: String; nTemp: LongInt; begin sTemp := ''; if (nAmount > 99) then begin nTemp := nAmount div 100; sTemp := sTemp + AWords[nTemp] + ' Hundred'; nAmount := nAmount - (nTemp * 100); if nAmount > 0 then sTemp := sTemp + #32; end; {if (nAmount > 99)} if ( nAmount > 0 ) and (nAmount < 20) then sTemp := sTemp + AWords[nAmount] else if ( nAmount > 19 ) then begin nTemp := nAmount div 10; sTemp := sTemp + AWords[nTemp + 18]; nAmount := nAmount - nTemp * 10; if (nAmount <> 0) then sTemp := sTemp + '-' + AWords[nAmount]; end; {if ( nAmount > 0 ) and (nAmount < 20)} Result := sTemp; end; { Static Function NWord() } (*********************** Immediate IF String ************************** IIFS(<bCond>, <sTrue>, <sFalse>) - Evaluates <bCond>. If true, the string <sTrue> is returned; if false, the string <sFalse> is returned. Example: sTestResult := 'Your score was ' + IIFS((passed), 'passing', 'failing'); ***********************************************************************) function IIFS( bCond: Boolean; sTrue, sFalse: String): String; begin if (bCond) then Result := sTrue else Result := sFalse; end; {function IIFS()} begin cString := ''; XX := 6; while (XX > -3) do begin dPow := Pow( 10, XX ); if (dAmount >= dPow) then begin iTemp := Trunc(dAmount / dPow); cString := cString + NWord(iTemp) + IIFS( XX = 6, ' Million', IIFS( XX = 3, ' Thousand', '')); dAmount := dAmount - (iTemp * dPow); if (dAmount > 0) then cString := cString + #32; end; {if (dAmount >= dPow)} Dec( XX, 3 ); end; {while (XX > -3)} if ((dAmount - Trunc(dAmount)) > 0) then begin iTemp := Trunc(dAmount * 100); cString := cString + 'and ' + IntToStr(iTemp) + '/100ths'; end {if ((dAmount - Trunc(dAmount)) > 0)} else cString := cString + ' exactly'; Result := cString; end; {function NumToWords()} -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]