c# 通过数值计算小数位数

时间:2020-05-15 12:17:56   收藏:0   阅读:62
/// <summary>
/// 获取小数位数
/// </summary>
/// <param name="decimalV">小数</param>
/// <returns></returns>
public static int GetNumberOfDecimalPlaces(double decimalV)
{
    string[] temp = decimalV.ToString().Split(.);
    if (temp.Length == 2 && temp[1].Length > 0)
    {
        int index = temp[1].Length - 1;
        while (temp[1][index] == 0 && index-- > 0) ;
        return index + 1;
    }
    return 0;
}

/// <summary>
/// 获取小数位数
/// </summary>
/// <param name="decimalV">小数</param>
/// <returns></returns>
public static int GetNumberOfDecimalPlaces(decimal decimalV)
{
    string[] temp = decimalV.ToString().Split(.);
    if (temp.Length == 2 && temp[1].Length > 0)
    {
        int index = temp[1].Length - 1;
        while (temp[1][index] == 0 && index-- > 0) ;
        return index + 1;
    }
    return 0;
}

 

原文:https://www.cnblogs.com/lcawen/p/12893788.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!