■ 절상하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
using System; #region 절상하기 - Appreciate(value) /// <summary> /// 절상하기 /// </summary> /// <param name="value">값</param> /// <returns>원 단위 절상값</returns> public decimal Appreciate(decimal value) { decimal result = value; result /= 10m; result = Math.Ceiling(result); result = Math.Floor(result); result *= 10m; return result; } #endregion #region 절상하기 - Appreciate(value, digitCount) /// <summary> /// 절상하기 /// </summary> /// <param name="value">값</param> /// <param name="digitCount">자릿 수</param> /// <returns>절상 값</returns> public decimal Appreciate(decimal value, int digitCount) { if(digitCount < 0) { digitCount = -digitCount; decimal temporary = Convert.ToDecimal(Math.Pow(10, digitCount)); value = value * temporary; value = Math.Ceiling(value); value = value / temporary; } else if(digitCount > 0) { decimal temporary = Convert.ToDecimal(Math.Pow(10, digitCount)); value = value / temporary; value = Math.Floor(value); value = value * temporary; } else { value = Math.Ceiling(value); } return value; } #endregion |