How to can I achieve "Manipulation of data during looping"

Certified Associate Developer

Hello,

a!localVariables(
local!number: todecimal(370737340900000.00), /* Replace this with your input number */
local!chunkSize: 7, /* Define chunk size (7 digits) */
local!divisor: 10 ^ local!chunkSize,

local!chunks: {}, /* List to store chunks */


local!x:a!forEach(
items: enumerate(ceiling(log(local!number)/log(local!divisor)) + 1), /* Arbitrarily large number to iterate through */
expression:{
local!iteration:enumerate(ceiling(log(local!number)/log(local!divisor)) + 1),
local!chunk: mod(local!number, local!divisor), /* Get last 7 digits */
local!number: round(local!number / local!divisor, 0)
}

),

/* Reverse the chunks list to maintain the correct order */
reverse(local!chunks)
)

I want to achieve try to split the big decimal into 7 digit numbers, I want the result in the "local!x" {8765431, 7373409, 370}

I hope the question is clear, let me know how to achieve this.

  Discussion posts and replies are publicly visible

Parents
  • There can be other ways of achieving this too.

    a!localVariables(
      local!number: "37073734098765431", /* Replace this with your input number */
      local!chunkSize: 7, /* Define chunk size (7 digits) */
      local!chunks: {}, /* List to store chunks */
      local!x:reverse(code(local!number)),
    
      /* Reverse the chunks list to maintain the correct order */
      a!forEach(
        items: enumerate(ceiling(length(local!x)/local!chunkSize))+1,
        expression: tointeger(joinarray(
          reverse(char(reject(
          a!isNullOrEmpty,
          index(
            local!x,
            enumerate((local!chunkSize))+if(fv!isFirst,1,(local!chunkSize*(fv!item-1))+1),
            null
          )
        )))
        ))
      )
    )

Reply
  • There can be other ways of achieving this too.

    a!localVariables(
      local!number: "37073734098765431", /* Replace this with your input number */
      local!chunkSize: 7, /* Define chunk size (7 digits) */
      local!chunks: {}, /* List to store chunks */
      local!x:reverse(code(local!number)),
    
      /* Reverse the chunks list to maintain the correct order */
      a!forEach(
        items: enumerate(ceiling(length(local!x)/local!chunkSize))+1,
        expression: tointeger(joinarray(
          reverse(char(reject(
          a!isNullOrEmpty,
          index(
            local!x,
            enumerate((local!chunkSize))+if(fv!isFirst,1,(local!chunkSize*(fv!item-1))+1),
            null
          )
        )))
        ))
      )
    )

Children
No Data