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?
 

klaus

Expert
Licensed User
Longtime User
@klaus suggestion is correct only for integer values.
Sorry, but this is wrong.
Min and Max work with Doubles !
I tested it before posting.

From the help:
1645107934043.png
 
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
Top