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

numbers, rounding, vb.net

Solution

You can use `Math.Max` to do it:

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

Problem

Is there a built in VB function to ensure the following: ``` Dim price Dim subsidy if price - subsidy <= 0 then price = 0 end if ``` In practical terms, I've lots of other things going on to calculate price, so I want to simplify this to: ``` Dim price = calculatedPrice - subsidy ``` and wrap that into some VB formatting that ensures if `price` ever becomes negative it's forced to zero. I'm thinking that a simple type conversion might do it, but am not sure which type would suit.

Original source