"Auto" decimal precision

I often find myself wanting to show numbers to the minimum number of decimal places required like in the leftmost column in the image below.

The leftmost column is a javascript column in which you can simply return a number value and it automatically shows it to the minimum number of decimal places required.

I’d like to see an “auto” decimal precision option for any number related column types where it does this for you, without needing extra columns.

Hola!

I think the toFixed() method in JavaScript can help as workaround to get the specified number of decimals that you want to.

Saludos!

Hey Gustavo,

Thanks! I can get the output I need by just returning the variable in a JS column as shown. It should always return the minimum number of decimals (or none) - basically need it to remove trailing zeros but then also show just the integer in the case of 1.000

Ah ok… I got it!

This new JS code can help you:

// take the integer part
intNum=Math.trunc(p1);

// take the decimals part as a text
decNum= p1.toString().split('.')[1]

if (!decNum)        // the Number is integer 100%?
   return intNum   //  shows Number and exits

// Invert decimal part  
var RevdecNum1 = decNum.split("").reverse().join("");  

// Convert it to Number and then to Text to remove trailing zeros
 RevdecNum2 = parseInt(RevdecNum1).toString()

// Invert it again to get right decimals
var RevdecNum3 = RevdecNum2.split("").reverse().join("");  

// Show your new number
return intNum+"."+RevdecNum3 

Feliz fin de semana James!!