Forum Discussion

ThomasUmphres's avatar
ThomasUmphres
Community Member
10 months ago

Javascript to Return a Number Variable to Show Exactly 3 Decimals

I have two variables called "AGCFreq" and "FreqRandom". They need to be exactly 3 decimal places. Even if "AGCFreq" = 60.020, it needs to display as 60.020. A randomized number between 0.022 and 0.045 will then be added to the 60.000. This number will then go through a different calculation script. 

The problem is no matter how I write this script, it's only showing up as 2 decimal places.

Does anyone have any tips on how to display this correctly?

  • You can return it to a numeric variable for internal calculations, but for display you have to return it to a text variable, or trailing 0s will be dropped.

  • Walt, thanks. I doubt a text variable can be used in a formula later on. I found a workaround in this instance. But I'll keep that in mind. 

    Really appreciate your replies, Brian and Walt.

  • It will have to be a text variable as Walt says to maintain three decimal places, you can then do any subsequent calculations using javascript