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!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...