Skip to main content
richardm900458
Inspiring
Aug 31, 2021 9:26 AM UTC
Question

Wrong calculation by Appian?

Hi together,

I have the following calculation:

ri!timstamp(decimal)="1630391405000"

if(
  isnull(ri!timestamp),
  todatetime(null),
  a!localVariables(
    local!hours: floor(ri!timestamp/1000/60/60),
    local!hoursMilli: local!hours*1000*60*60,
    local!tsMinusHours: ri!timestamp - local!hoursMilli,
    local!minutes: floor(local!tsMinusHours/1000/60),
    local!minutesMilli: local!minutes*1000*60,
    local!tsMinusMinutes: local!tsMinusHours - local!minutesMilli,
    local!tsMinusMinutes
  )
)
result 5000(decimal)

if(
  isnull(ri!timestamp),
  todatetime(null),
  a!localVariables(
    local!hours: floor(ri!timestamp/1000/60/60),
    local!hoursMilli: local!hours*1000*60*60,
    local!tsMinusHours: ri!timestamp - local!hoursMilli,
    local!minutes: floor(local!tsMinusHours/1000/60),
    local!minutesMilli: local!minutes*1000*60,
    local!tsMinusMinutes: local!tsMinusHours - local!minutesMilli,
    local!seconds: todecimal(quotient(local!tsMinusHours, 1000.00)),
    local!seconds
  )
)

result 1805(decimal)  - expected 5


addition: the "todecimal" was already a try to fix it as i could imagine that it was perhaps a format issue.


5000/1000 results into 1805 instead of 5 and i absolutly dont get why it happens.
quotient() gives the same result as I would divide it via "/"
Any ideas?

3 replies

harshas2775
Brainy
Aug 31, 2021 10:33 AM UTC

Looks like in line 28 you have mistakenly done quotient on local!tsMinusHours instead of local!tsMinusMinutes. Correcting that should resolve the issue.

Happy to help. Even happier to optimize.
richardm900458
Inspiring
Aug 31, 2021 11:36 AM UTC

my hero.... thank you very much.
-> two lead developers and one senior developer havn't seen this and this rule is productive since 2018. 

harshas2775
Brainy
Sep 1, 2021 4:26 AM UTC

haha it happens to the best of us! Glad I could be of help!

Happy to help. Even happier to optimize.