Skip to main content
September 19, 2024
Solved

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

  • September 19, 2024
  • 4 replies
  • 0 views

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.

Best answer by stefanhelzle0001

a!localVariables(
  local!value: 370737340900000.00,
  local!chunkSize: 3,
  local!textValue: text(local!value, "0"),
  a!forEach(
    items: enumerate(ceiling(len(local!textValue) / local!chunkSize)),
    expression: mid(local!textValue, (fv!item * local!chunkSize) + 1, local!chunkSize)
  )
)

4 replies

somasundaram.d
September 19, 2024

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
      )
    )))
    ))
  )
)

kumara0180
September 19, 2024

a!localVariables(
  local!text: char(
    code(
      "21121212u1i2ui12i1iwjansjnajnsjansnansa"
    )
  ),
  local!length: 7,
  
  local!arrayWithIdentifier: a!flatten(
    a!forEach(
      items: local!text,
      expression: {
        if(
          mod(fv!index, local!length) = 0,
          { fv!item, ";" },
          { fv!item }
        )
      }
    )
  ),
  local!splitData: split(concat(local!arrayWithIdentifier), ";"),
  local!splitData
)

stefanhelzle0001
September 19, 2024

a!localVariables(
  local!value: 370737340900000.00,
  local!chunkSize: 3,
  local!textValue: text(local!value, "0"),
  a!forEach(
    items: enumerate(ceiling(len(local!textValue) / local!chunkSize)),
    expression: mid(local!textValue, (fv!item * local!chunkSize) + 1, local!chunkSize)
  )
)

kumara0180
September 19, 2024

Thanks [mention:a11f77a729fb4db2af76b09948583328:e9ed411860ed4f2ba0265705b8793d05] , Much easier