Android Question Doing Min() and Max() at the same time?

wimpie3

Well-Known Member
Licensed User
Longtime User
Is there a way to simplify this code?

B4X:
If percentage < 0 Then percentage=0
If percentage > 1 Then percentage=1

It's a combination of Min and Max but I'm not sure such a function exists?
 

Mahares

Expert
Licensed User
Longtime User
How about another variant:
B4X:
Log(IIf( percentage < 0, 0, IIf(percentage > 1, 1, percentage)))
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Perhaps I misunderstood the original requirement. I assumed that the actual requirement was for percentage to end up with a value of either 0 or 1. The original code in the first post would do that for integer values but not doubles. It would leave it unchanged for the values from 0 to 0.99999.... That is why I asked for clarification in post #2.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…