Arcade expression for formatting a number into Station+ (Plus) format in WebMap Popup

7515
10
07-16-2018 09:59 AM
MichaelWalden1
New Contributor II

Arcade expression for formatting a number into Station+ (Plus) format in WebMap Popup

I am trying to the equivalent Arcade expression for the following VBScript: 

Function FindLabel ( [Station] )
if (LEN(ROUND([Station],0))) = "7" then
FindLabel = LEFT(ROUND([Station],0),5) + "+" + RIGHT(ROUND([Station],0),2)
elseif (LEN(ROUND([Station],0))) = "6" then
FindLabel = LEFT(ROUND([Station],0),4) + "+" + RIGHT(ROUND([Station],0),2)
elseif (LEN(ROUND([Station],0))) = "5" then
FindLabel = LEFT(ROUND([Station],0),3) + "+" + RIGHT(ROUND([Station],0),2)
elseif (LEN(ROUND([Station],0))) = "4" then
FindLabel = LEFT(ROUND([Station],0),2) + "+" + RIGHT(ROUND([Station],0),2)
elseif (LEN(ROUND([Station],0))) = "3" then
FindLabel = LEFT(ROUND([Station],0),1) + "+" + RIGHT(ROUND([Station],0),2)
elseif (LEN(ROUND([Station],0))) = "2" then
FindLabel = LEFT(ROUND([Station],0),0) + "0+" + RIGHT(ROUND([Station],0),2)
elseif (LEN(ROUND([Station],0))) = "1" then
FindLabel = LEFT(ROUND([Station],0),0) + "0+0" + RIGHT(ROUND([Station],0),2)
else
FindLabel = ROUND([Station],0)
end if
End Function

It appears there is not an Arcade text/string LENGTH function to be able to return the number of characters.  Is there another way to format a number with varying digits/characters to take the last 2 digits for the record and insert a "+" before those 2 digits.

Example

VALUE      STATION

639249      6392+49

11715        117+15

234            2+34

0 Kudos
10 Replies
XanderBakker
Esri Esteemed Contributor

Hi Steven Weaver , 

I have the feeling that there is a division missing in your expression. 

var station = 123456; // $feature.BeginStation;
var len = Count(Text(station))
var end = Text(station/100, "00.00")
var labelStation =""
var leftVal = len - 4
var start = Left(station, leftVal)
if (start=="") {
start="0";
}
labelStation = start + '+' + end

Using the value 123456 it results in "12+34.56". Are you looking for something like this?

0 Kudos