I'm using Appian Version 21.4 and I has a task to convert number to word, I tried to use "convertnumbertoword" function but it is not exists.
Can some one help me to achieve this task?
Discussion posts and replies are publicly visible
use a!match() to enumerate your various permutations instead of nested IFs. It's easier to look at and will probably be easier to maintain / troubleshoot / etc.
I have created two rules in Appian to achieve it using the standard logic. This works for negative values as well.Rule to convert number into words: APN_convertNumberToWord
if( rule!APN_isNull(ri!value), null, a!localVariables( local!units: { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" }, local!tens: { "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }, local!thousands: { " Hundred", " Thousand", " Million", " Billion", " Trillion" }, local!sign: if(ri!value < 0, "- ", ""), local!words: a!match( value: abs(ri!value), whenTrue: fv!value < 20, then: if( floor(fv!value) = 0, "", local!units[floor(fv!value)] ), whenTrue: fv!value < 100, then: concat( local!tens[floor(fv!value / 10)], if( mod(fv!value, 10) <> 0, concat( " ", local!units[floor(mod(fv!value, 10))] ), "" ) ), whenTrue: fv!value < 1000, then: concat( local!units[floor(fv!value / 100)], local!thousands[1], if( mod(fv!value, 100) <> 0, concat( " and ", rule!APN_convertNumberToWord(value: mod(fv!value, 100)) ), "" ) ), whenTrue: fv!value < 1000000, then: concat( rule!APN_convertNumberToWord(value: fv!value / 1000), local!thousands[2], if( mod(fv!value, 1000) <> 0, concat( " ", rule!APN_convertNumberToWord(value: mod(fv!value, 1000)) ), "" ) ), whenTrue: fv!value < 1000000000, then: concat( rule!APN_convertNumberToWord(value: fv!value / 1000000), local!thousands[3], if( mod(fv!value, 1000000) <> 0, concat( " ", rule!APN_convertNumberToWord(value: mod(fv!value, 1000000)) ), "" ) ), whenTrue: fv!value < 1000000000000, then: concat( rule!APN_convertNumberToWord(value: fv!value / 1000000000), local!thousands[4], if( mod(fv!value, 1000000000) <> 0, concat( " ", rule!APN_convertNumberToWord(value: mod(fv!value, 1000000000)) ), "" ) ), whenTrue: fv!value < 1000000000000000, then: concat( rule!APN_convertNumberToWord(value: fv!value / 1000000000000), local!thousands[5], if( mod(fv!value, 1000000000000) <> 0, concat( " ", rule!APN_convertNumberToWord(value: mod(fv!value, 1000000000000)) ), "" ) ), default: "Number too large" ), local!sign & local!words ) )
Rule to convert decimal values and adding currency sign: APN_convertCurrencyNumberToWords
if( or(rule!APN_isNull(ri!value), ri!value = 0), null, a!localVariables( local!currencyCode: rule!APN_replaceNull( originalValue: ri!currencyCode, replacedValue: cons!APN_TEXT_DEFAULT_CURRENCY_ISO_CODE ), local!currencies: rule!APN_QR_getBasicGeneric( recordType: 'recordType!{a510caa6-ed25-4610-8902-6d74a4be5ab1}APN Ref Currency', fields: { 'recordType!{a510caa6-ed25-4610-8902-6d74a4be5ab1}APN Ref Currency.fields.{768897bb-1ff7-4e7c-b6e1-a1d219ebe210}majorName', 'recordType!{a510caa6-ed25-4610-8902-6d74a4be5ab1}APN Ref Currency.fields.{f4be1ed5-f70a-48c8-94b5-6becd739ad61}minorName' }, filters: { a!queryFilter( field: 'recordType!{a510caa6-ed25-4610-8902-6d74a4be5ab1}APN Ref Currency.fields.{e0d23fba-5755-4c28-897c-6dc9d82d57c8}currencyCode', operator: "=", value: local!currencyCode ), a!queryFilter( field: 'recordType!{a510caa6-ed25-4610-8902-6d74a4be5ab1}APN Ref Currency.fields.{c08a8ab4-5019-4762-a684-e699a055a489}isActive', operator: "=", value: true() ) }, pagingInfo: rule!APN_defaultPagingInfo(), fetchTotalCount: false(), returnOnlyData: true() ), local!majorName: property( local!currencies, 'recordType!{a510caa6-ed25-4610-8902-6d74a4be5ab1}APN Ref Currency.fields.{768897bb-1ff7-4e7c-b6e1-a1d219ebe210}majorName', null ), local!minorName: property( local!currencies, 'recordType!{a510caa6-ed25-4610-8902-6d74a4be5ab1}APN Ref Currency.fields.{f4be1ed5-f70a-48c8-94b5-6becd739ad61}minorName', null ), local!majorValue: floor(ri!value), local!minorValueHold: (ri!value - local!majorValue) * 100, local!minorValue: if( ri!value < 0, 100 - local!minorValueHold, local!minorValueHold ), if( local!minorValue > 0, concat( rule!APN_convertNumberToWord(value: ri!value), " ", local!majorName, if(local!majorValue > 1, "s", ""), " and ", rule!APN_convertNumberToWord(value: tointeger(local!minorValue)), " ", local!minorName, if(local!minorValue > 1, "s", "") ), concat( rule!APN_convertNumberToWord(value: local!majorValue), " ", local!majorName, if(local!majorValue > 1, "s", "") ) ) ) )
Major and minor currency names can be stored into a generic currency table as follows: