Labeling and an extra zero

97
2
Jump to solution
01-03-2022 09:46 AM
JasonSimpson
New Contributor III

Good afternoon, I am running into an issue when labeling on the new map viewer. For some reason, my arcade script is adding zeros onto a currency field.  Below is my script. Can anyone advise me on what I may be doing wrong. Thanks.  Below is my scripts

if ($feature.Change > 0 ) {return Text($feature["Change"], '$##,###,###' + ' - '+ Round(($feature["F__Change"])*100,2)+ "%")}

This turns a value of $1,900 into $190,000

 

 

1 Solution

Accepted Solutions
jcarlson
MVP Honored Contributor

Just to follow up, it was a combination of issues.

  1. Your Text function included the hyphen and percentage as part of the formatting string
  2. Your formatting string included a "%" as a result of #1

It's lower down in the Function Reference page, but you can see that when "%" appears in the formatting string, it will multiply by 100 and format as a percentage.

jcarlson_0-1641245137779.png

By moving the parenthesis, the "%" is no longer in the formatting string, and the function won't trigger the multiplying by 100.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
2 Replies
jcarlson
MVP Honored Contributor

Does the expression evaluate properly in other contexts, like in Pro or a Dashboard? At a glance, it looks like you're missing a closing parenthesis after your text formatting string.

return Text($feature["Change"], '$##,###,###' +...

I'm only working with hard-coded variables, since I don't have a layer handy to test this on, but I can't replicate the issue:

jcarlson_0-1641236748565.png

What you might try, though, is to establish variables and use template literals for your string, and see if that behaves any differently. At the very least, it's a nicer way of writing strings with multiple parts.

var c = $feature["Change"];
var f = $feature["F__Change"];

if (c > 0 ) {
    return `${Text(c, '$##,###,###')} - ${Round(f * 100, 2)}%`
}

 

- Josh Carlson
Kendall County GIS
jcarlson
MVP Honored Contributor

Just to follow up, it was a combination of issues.

  1. Your Text function included the hyphen and percentage as part of the formatting string
  2. Your formatting string included a "%" as a result of #1

It's lower down in the Function Reference page, but you can see that when "%" appears in the formatting string, it will multiply by 100 and format as a percentage.

jcarlson_0-1641245137779.png

By moving the parenthesis, the "%" is no longer in the formatting string, and the function won't trigger the multiplying by 100.

- Josh Carlson
Kendall County GIS
0 Kudos