Force calculation result if less than zero to zero in VB.net

Is there a built-in VB function to provide the following:

Dim price
Dim subsidy

if price - subsidy <= 0 then 
    price = 0
end if

In practical terms, I have many other things to calculate the price, so I want to simplify this:

Dim price = calculatedPrice - subsidy

and wrap it in some VB formatting, which ensures that if priceit ever becomes negative, it will be forced equal to zero.

I think a simple type conversion can do this, but I'm not sure which type suits.

+3
source share
1 answer

You can use Math.Max:

Dim price = Math.Max(calculatedPrice - subsidy, 0)
+5
source

All Articles