cancel
Showing results for 
Search instead for 
Did you mean: 

Function to convert number to words in Powerbuilder

Former Member
0 Kudos
915

Dear All ,

Any body know where I can get a Function to convert number to words in Powerbuilder .

Regards ,,, Moayad

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

An example PB application (pb_pronounce.zip) is available here:

https://groups.yahoo.com/neo/groups/powerobject/files/PowerBuilder/

HTH

Former Member
0 Kudos

Hi Everybody  ,

Thank you for your help , I have downloaded the script bu unfortunately is giving wrong

words , any how I am going to use MS SQL function can you let me know how can

call the function to return the number in word using  pb12.5 , find below the function that I am going to use .


Regards ,,, Moayad



/****** Object:  UserDefinedFunction [dbo].[fnNumberToWords]    Script Date: 05/03/2016 21:18:31 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

/*SELECT NumberInEnglish=dbo.fnNumberToWords ( 947)

-- Nine Hundred Forty-Seven

SELECT NumberInEnglish=dbo.fnNumberToWords ( 984261)

-- Nine Hundred Eighty-Four Thousand Two Hundred Sixty-One

*/

CREATE FUNCTION [dbo].[fnNumberToWords](@Number as BIGINT)

    RETURNS VARCHAR(1024)

AS

BEGIN

      DECLARE @Below20 TABLE (ID int identity(0,1), Word varchar(32))

      DECLARE @Below100 TABLE (ID int identity(2,1), Word varchar(32))

      INSERT @Below20 (Word) VALUES

                        ( 'Zero'), ('One'),( 'Two' ), ( 'Three'),

                        ( 'Four' ), ( 'Five' ), ( 'Six' ), ( 'Seven' ),

                        ( 'Eight'), ( 'Nine'), ( 'Ten'), ( 'Eleven' ),

                        ( 'Twelve' ), ( 'Thirteen' ), ( 'Fourteen'),

                        ( 'Fifteen' ), ('Sixteen' ), ( 'Seventeen'),

                        ('Eighteen' ), ( 'Nineteen' )

       INSERT @Below100 VALUES ('Twenty'), ('Thirty'),('Forty'), ('Fifty'),

                               ('Sixty'), ('Seventy'), ('Eighty'), ('Ninety')

DECLARE @English varchar(1024) =

(

  SELECT Case

    WHEN @Number = 0 THEN  ''

    WHEN @Number BETWEEN 1 AND 19

      THEN (SELECT Word FROM @Below20 WHERE ID=@Number)

   WHEN @Number BETWEEN 20 AND 99 

     THEN  (SELECT Word FROM @Below100 WHERE ID=@Number/10)+ '-' +

           dbo.fnNumberToWords( @Number % 10)

   WHEN @Number BETWEEN 100 AND 999 

     THEN  (dbo.fnNumberToWords( @Number / 100))+' Hundred '+

         dbo.fnNumberToWords( @Number % 100)

   WHEN @Number BETWEEN 1000 AND 999999 

     THEN  (dbo.fnNumberToWords( @Number / 1000))+' Thousand '+

         dbo.fnNumberToWords( @Number % 1000)

   WHEN @Number BETWEEN 1000000 AND 999999999 

     THEN  (dbo.fnNumberToWords( @Number / 1000000))+' Million '+

         dbo.fnNumberToWords( @Number % 1000000)

   WHEN @Number BETWEEN 1000000000 AND 999999999999 

     THEN  (dbo.fnNumberToWords( @Number / 1000000000))+' Billion '+

         dbo.fnNumberToWords( @Number % 1000000000)

   WHEN @Number BETWEEN 1000000000000 AND 999999999999999 

     THEN  (dbo.fnNumberToWords( @Number / 1000000000000))+' Trillion '+

         dbo.fnNumberToWords( @Number % 1000000000000)

  WHEN @Number BETWEEN 1000000000000000 AND 999999999999999999 

     THEN  (dbo.fnNumberToWords( @Number / 1000000000000000))+' Quadrillion '+

         dbo.fnNumberToWords( @Number % 1000000000000000)

  WHEN @Number BETWEEN 1000000000000000000 AND 999999999999999999999 

     THEN  (dbo.fnNumberToWords( @Number / 1000000000000000000))+' Quintillion '+

         dbo.fnNumberToWords( @Number % 1000000000000000000)

        ELSE ' INVALID INPUT' END

)

SELECT @English = RTRIM(@English)

SELECT @English = RTRIM(LEFT(@English,len(@English)-1))

                 WHERE RIGHT(@English,1)='-'

RETURN (@English)

END

GO

Former Member
0 Kudos

Hi Moayad;

  You could probably adapt one of these code segments to your needs ...

Option#1:  Convert Numbers into Words • PowerBuilder Elegant Code Club

Option#2:  SAP Sybase Forums - PowerBuilder - PowerBuilder Foundation Classes (PFC) - Number to Words

HTH

Regards ... Chris