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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...