Skip to main content
February 13, 2022
Solved

Convert Number To Word

  • February 13, 2022
  • 12 replies
  • 1 view

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?

Best answer by stefanhelzle0001

I think that does not exist in Appian. But that is a well known algorithm with many implementations. That would be a nice challenge for the community to solve.

stackoverflow.com/.../algorithm-that-converts-numeric-amount-into-english-words

12 replies

stefanhelzle0001
February 13, 2022

What exactly do you want to achieve? Convert "100" to "onehundred"?

February 13, 2022

yes

stefanhelzle0001
February 13, 2022

I think that does not exist in Appian. But that is a well known algorithm with many implementations. That would be a nice challenge for the community to solve.

stackoverflow.com/.../algorithm-that-converts-numeric-amount-into-english-words

harshitb6843
February 13, 2022

This is one of my favorite challenges in Appian that I offer to people who want to solve some complex problems [emoticon:44a8a53ad3364ea78a16c5a3229f75bb]

peter.lewis
Employee
February 14, 2022

There is an existing plugin that does this: community.appian.com/.../convert-number-to-word

February 15, 2022

this plugin not exists 

stewart.burchell
February 15, 2022

Not sure what you mean by "this plugin not exists" - I've just followed the link that [mention:6b9f80ff18f9420082d13ef2d5121d56:e9ed411860ed4f2ba0265705b8793d05] provided and it does indeed exist. You have to have it installed in your environment in order to use it.

August 22, 2022

without plugin, I have solved but its for 3 digit number,
but we can do it for 2 digit and more.

a!localVariables(
  local!num: tostring(ri!num),
  local!o: {
    "",
    "One",
    "Two",
    "Three",
    "Four",
    "Five",
    "Six",
    "Seven",
    "Eight",
    "Nine"
  },
  local!t: {
    "Ten",
    "Twenty",
    "Thirty",
    "Forty",
    "Fivty",
    "Sixty",
    "Sventy",
    "Eighty",
    "Ninty"
  },
  local!ele: {
    "",
    "Eleven",
    "Twelve",
    "Thirteen",
    "Forteen",
    "Fifteen",
    "Sixteen",
    "Seventeen",
    "Eighteen",
    "Ninteen"
  },
  local!digit: a!forEach(
    items: enumerate(len(local!num)),
    expression: tointeger(local!num[fv!index])
  ),
  if(
    len(local!num) = 3,
    concat(
      local!o[index(local!digit, 1, {}) + 1],
      " ",
      "Hundred",
      " ",
      if(
        local!digit[2] = 0,
        {},
        if(
          and(local!digit[2] = 1, local!digit[3] = 0),
          local!t[index(local!digit, 2, {})],
          if(
            local!digit[2] = 1,
            {},
            local!t[index(local!digit, 2, {})]
          )
        )
      ),
      " ",
      if(
        local!digit[3] = 0,
        {},
        if(
          local!digit[2] = 1,
          local!ele[index(local!digit, 3, {}) + 1],
          local!o[index(local!digit, 3, {}) + 1]
        )
      )
    ),
    {}
  )
)

August 22, 2022

please suggest some changes as well !

richardm900458
August 22, 2022

hi try to use
 

makes our live easier to support you easier

harshk1671
April 16, 2025

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: