AG Grid Value Formatter

I’m currently using the following AG Grid formatting statement to add a dollar sign in front of float values in a column. How can I modify this statement so that a comma is added for every 3 orders of magnitude (thousands, milions, billions, etc)?
"valueFormatter": {"function": "'$' + (params.value ? params.value : 0)"}

Hello @adiadidas15,

I’d use the built-in d3 thats available:

"valueFormatter": {"function": "params.value ? d3.format('$(,.2f')(params.value) : null"}

Thanks @jinnyzor! That almost worked. It has an extra open parenthesis. Here’s the corrected statement: "valueFormatter": {"function": "params.value ? d3.format('$,.2f')(params.value) : null"}

I think I just had the parenthesis on the wrong side of the $. What I gave would have a negative amount with parenthesis.

I used my “fix” to your solution and it works fine. The original solution you provided has 5 parentheses, so it isn’t possible that a parenthesis was misplaced. Either there’s a missing parenthesis or there’s an extra parenthesis.

5 parentheses is correct.

It was just an issue with where the one was after the $ vs before.

1 Like