Splunk Search

What is the most elegant way to convert from float to currency in SPL?

nick405060
Motivator

Miraculously in 2020 there still hasn't been a Splunk Answer that details an elegant way to convert from float to currency.

Is this the best possible solution, or are there more elegant ways to do this? Careful of negative numbers.

eval budget_amount="$".tostring(budget_amount,"commas") | rex mode=sed field=budget_amount "s/\$$-/-$$/g"

0 Karma

spayneort
Contributor

How about:

|eval budget_amount=if(budget_amount>=0,"$".tostring(budget_amount,"commas"), "-$".tostring(abs(budget_amount),"commas"))
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...