One problem VB.NET developers usually face is how to truncate a decimal number to some specified number of digits after it without rounding off. The Math library doesn’t provide any method to do this. And almost all of the common functions that do similar job, round them off to specified number of digits instead of truncating them. e.g. The String.FormatNumber, String.Format, Math.Round etc. round off, and there doesn’t seem to be any native method to truncate it instead of rounding it off.
Fortunately, it’s easy to construct a function that does our job.
Function FixDecimal(ByVal number As Decimal, ByVal digits As Integer) As Decimal
Dim x As Integer = 10 ^ digits
Return Fix(number * x) / x
For ease of use, this may be declared a Public Shared member of class or as a Public member of a module, or maybe as an extension method, as the situation permits.