Jump to content
Server Maintenance This Week. ×

How to force calculation in layout to round to two decimals


This topic is 1564 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have a layout calculation that looks like:

Round(If($$NoGPABump = 1;Classes::GPANoBump; Classes::GPABumped);2)

In most instances, this rounds the appropriate value to 2 decimals  and displays those two digits.  But on occasion, it displays only one decimal as in this one:

image.png.c71290d1f0c6315902aaa0345baf7865.png.  Instead I want to see 4.20.  If I round to, say, 4 decimals, it works properly: image.png.a36b87c5140fbfdcbfdd61fa17c68447.png.  Rounding to 3 digits gives 4.199.  How do I get the trailing zero to show up?  This seems to be consistent for all data that rounds to a last digit of zero.  Is this a bug?  Is there a workaround?  Thanks,

 

Link to comment
Share on other sites

Thank you Kaizentu.  In this case the layout object is a button bar with a conditionally calculated title and there is no option to set the format of the object.  I've gotten used to using that technique a lot to display conditional or calculated text.  It's a great way to avoid creating another calculated field but seems to have this limitation.  I went back to the workaround for this - two instances of the field superimposed, using "Hide object when" to display the relevant one.  Any other option?  Thanks

Link to comment
Share on other sites

You can do your own formatting within the calculation, for example:

Let ( [
n = If ( $$NoGPABump = 1 ; Classes::GPANoBump ; Classes::GPABumped ) ;
r = Round ( n ; 2 )
] ;
Int ( r ) & SerialIncrement ( ".00" ; 100 * Mod ( r ; 1 ) )
)

Note that this assumes the number is not negative - otherwise the calculation needs to be a bit more complex.

 

Link to comment
Share on other sites

Wow, that's cool.  I never considered brute force calculating the formatted text.  I suppose I could write a custom function to support formatting rounded to a given number of decimals.  I guess I'm spoiled and used to platforms that have that kind of functionality built in.  For this one, however, I think the easiest solution is to use the field formatting with conditional visibility rather than the calculation.  Not too bad!

Thanks for the help

Link to comment
Share on other sites

This topic is 1564 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.