Splunk Search

How to convert decimal numbers to percentage?

auaave
Communicator

Hi guys,

With my below query, how can I convert the value of %Empty and %Occupied to Percentage instead of decimal? then add the % sign?
Thanks a lot!

| chart values(NOOFEMPTYLOCATIONS) AS EMPTY eval(values(NOOFLOCATIONS)-values(NOOFEMPTYLOCATIONS)) as OCCUPIED eval(values(NOOFEMPTYLOCATIONS)/values(NOOFLOCATIONS)) as %EMPTY eval((values(NOOFLOCATIONS)-values(NOOFEMPTYLOCATIONS))/values(NOOFLOCATIONS)) as %OCCUPIED by Aisle

0 Karma
1 Solution

493669
Super Champion

try:

...|eval %EMPTY =round(%EMPTY*100)."%", %OCCUPIED=round(%OCCUPIED*100)."%"

View solution in original post

niketn
Legend

@auaave when you are aliasing the field name it is better you do not have special character i.e. %. That should be your final step before presenting to users i.e. | rename EMPTY_PERC as "Empty %"

Which is the visualization you are using? Most Visualization settings allow you to round off the value without decimal using Number Formatting and also change the display unit as per your needs like %, KBs etc.

In other words if you can give your current output with expected, the solution can be directly in UI Edit options to Format Visualization

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

auaave
Communicator

@niketnilay, thanks a lot for your advise. I will be using the stacked column chart for the %empty and %occupied, then include the statistics with the values.

0 Karma

HiroshiSatoh
Champion

When changing only display

|fieldformat %EMPTY=tostring('%EMPTY'*100)."%"
|fieldformat %OCCUPIED=tostring('%OCCUPIED'*100)."%"

493669
Super Champion

try:

...|eval %EMPTY =round(%EMPTY*100)."%", %OCCUPIED=round(%OCCUPIED*100)."%"

HiroshiSatoh
Champion

I got an error so I fixed it

...|eval %EMPTY=round('%EMPTY'*100)."%", %OCCUPIED=round('%OCCUPIED'*100)."%"
0 Karma

auaave
Communicator

thanks @493669 and @HiroshiSatoh! this works for me! Appreciate your help guys! 🙂

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 ...