첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------

[C#/COMMON] 절사하기

C#/Common 2014. 12. 31. 09:00
728x90
728x170
#region 절사하기 - CutOff(value, digitCount)

/// <summary>
/// 절사하기
/// </summary>
/// <param name="value">값</param>
/// <param name="digitCount">자릿 수</param>
/// <returns>절사 값</returns>
/// <remarks>
/// 양수 : 정수 자릿수 이하 절사한다.
/// 음수 : 소수 자릿수 이하 절사한다.
/// </remarks>
public decimal CutOff(decimal value, int digitCount)
{
    decimal result               = value;
    int     absolutiveDigitCount = Math.Abs(digitCount);

    if(digitCount > 0)
    {
        for(int i = 0; i < absolutiveDigitCount; i++)
        {
            result /= 10;
        }

        result = Math.Truncate(result);

        for(int i = 0; i < absolutiveDigitCount; i++)
        {
            result *= 10;
        }
    }
    else
    {
        for(int i = 0; i < absolutiveDigitCount; i++)
        {
            result *= 10;
        }

        result = Math.Truncate(result);

        for(int i = 0; i < absolutiveDigitCount; i++)
        {
            result /= 10;
        }
    }

    return result;
}

#endregion
728x90
그리드형(광고전용)
Posted by icodebroker
,