Let's start this problem today, and I wrote a function for it. In my particular case, I needed to make sure that all values ββare at least 0 (hence the name "LT0") and rounded to two decimal places.
Private Function LT0(ByVal Input As Decimal, Optional ByVal Precision As Int16 = 2) As Decimal ' returns 0 for all values less than 0, the decimal rounded to (Precision) decimal places otherwise. If Input < 0 Then Input = 0 if Precision < 0 then Precision = 0 ' just in case someone does something stupid. Return Decimal.Round(Input, Precision) ' this is the line everyone probably looking for. End Function
source share