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!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...