Select to view content in your preferred language

Multiplying and Dividing Variables in Arcade

1568
3
Jump to solution
08-21-2023 08:09 PM
Labels (1)
Bbean
by
New Contributor II

I need a little help with some Arcade formatting in my attribute rules. I have a valid Arcade expression made to return a number, but I am having some issues with a variable doing a mathematical expression. 

The variable InletVolume in the following example is supposed to multiply the variable D by 216, then divide it by 1728 then divide it by 27, but all it will return is 0. I have made sure the If/Else expressions are right, and if I just put it as InletVolume = D it gives the right number, but when I ask it to do any calculation such as D * 10 it just returns a 0. I am guessing that I have the formatting wrong for it, but I have tried everything I can think of with it, adding parenthesis, brackets, etc. 

Any help you could provide would be great!

Bbean_0-1692673623711.png

Var StructType = $feature.StructureType
var SubType = $feature.Subtype
var D = $feature.DebrisDepth
var B = $feature.BoxDiamIn
var InletVolume = D * 216 / 1728 / 27
var PrereatVol = (((D * B) / 1728) / 27)
var ManholeVolume = 0
var UntrackedVolume = 0

if (StructType == "SD INLET") {
   return InletVolume;
}  else if (StructType == "PRE-TREATMENT STRUCTURE") {
   return PretreatVol;
}  else if (StructType == "SD MANHOLE") {
   return ManholeVolume;
}  else {
   return UntrackedVolume;
}

Tags (2)
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Possible error sources:

  • null values are treated as 0. D=null will return 0, so make sure you actually have values in DebrisDepth.
  • for D<216, your result will be smaller than 1. If your target field is an integer field, these will be rounded down to 0. Make sure that your target field is a double field.
  • Make sure that your StructureType is actually "SD INLET", else the rule will return UntrackedVolume
  • You have a typo: PrereatVol should be PretreatVol

Have a great day!
Johannes

View solution in original post

0 Kudos
3 Replies
JohannesLindner
MVP Frequent Contributor

Possible error sources:

  • null values are treated as 0. D=null will return 0, so make sure you actually have values in DebrisDepth.
  • for D<216, your result will be smaller than 1. If your target field is an integer field, these will be rounded down to 0. Make sure that your target field is a double field.
  • Make sure that your StructureType is actually "SD INLET", else the rule will return UntrackedVolume
  • You have a typo: PrereatVol should be PretreatVol

Have a great day!
Johannes
0 Kudos
Bbean
by
New Contributor II

Thanks for your help! It turns out that the issue is the second point that you brought up, and I went ahead and changed it over to double with number format to allow 10 decimal places, but it seems to only allow 1 decimal place, and is now returning 0.1 when it should in reality be like .005. Is there something I need to do to allow multiple decimal places in the arcade calculations?

0 Kudos
Bbean
by
New Contributor II

Nevermind, I had the scale for the double set to 1 without knowing it. It is working properly now. I very much appreciate your help!

0 Kudos