Truncate number of digit of double value in C#

后端 未结 12 683
死守一世寂寞
死守一世寂寞 2020-12-30 04:35

How can i truncate the leading digit of double value in C#,I have tried Math.Round(doublevalue,2) but not giving the require result. and i didn\'t find any other method in M

12条回答
  •  醉梦人生
    2020-12-30 05:01

    For vb.net use this extension:

    Imports System.Runtime.CompilerServices
    
    Module DoubleExtensions
    
        
        Public Function Truncate(dValue As Double, digits As Integer)
    
            Dim factor As Integer
            factor = Math.Pow(10, digits)
    
            Return Math.Truncate(dValue * factor) / factor
    
        End Function
    End Module
    

提交回复
热议问题