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!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...