We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Retain trailing zeros when using .toFixed

MBarrott
Mega Sage

I want to show a percentage value with two decimal places. Using toFixed(2);

 

Although working, it truncates the trailing zero (e.g. 93.10% becomes 93.1%). 

 

Is there any way to retain the truncated zero?

 

 

5 REPLIES 5

Anurag Tripathi
Mega Patron

Hi,

Can you show the script you are using?

-Anurag

Hi @Anurag Tripathi,

 

I'm calculating the value and storing in a variable, then applying toFixed.

 

 

percentCompleteGA = (inactiveGARows / totalGARows) * 100;
percentCompleteGA.toFixed(2)

 

 

 

It calculates correctly and displays correctly 99% of the time. Except when the second decimal is a zero, then it's truncated. 

if totalGARows is 0

Then you will get NaN. Is that right.

 

In that case I would suggest you add a check to see if  totalGARows is 0 then tjust throw 0.00 without calculation.

-Anurag

Hi @Anurag Tripathi

 

I don't think you're understanding the issue. 

When the value returned has a trailing zero i.e. 93.10 - then it displays as 93.1 - I would like it to display as 93.10