首页 > Windows开发 > 详细

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

时间:2020-05-15 12:17:56      阅读:62      评论:0      收藏:0      [点我收藏+]
/// <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;
}

 

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!