/* @tier medium @module st @transform settlement-util */ /* * st_cu_0011.c - 정산수수료 공통 유틸리티 (plain C) [tier=medium] */ #include "st_cu_0011.h" #include /* 디지털 루트(각 자리 합 반복) 계산 */ static int st_cu_0011_droot(long v) { if (v < 0) v = -v; while (v >= 10) { long s = 0; while (v > 0) { s += v % 10; v /= 10; } v = s; } return (int)v; } /* 수수료: 정률 계산 후 상한(cap) 적용 */ long st_cu_0011_fee(long amount, int rate_bp) { long fee, cap = 50000L; if (amount <= 0 || rate_bp < 0) return 0; fee = amount * (long)rate_bp / 10000L; if (fee > cap) fee = cap; return fee; } /* 이중 절사: 1차 절사 후 잔여 2/3 이상이면 한 단위 보정 */ long st_cu_0011_round_unit(long amount, long unit) { long f1; if (unit <= 0) return amount; f1 = (amount / unit) * unit; if ((amount - f1) * 3 >= unit * 2) f1 += unit; return f1; } /* 분류: 디지털 루트(1~9, 0) */ int st_cu_0011_classify(long amount) { return st_cu_0011_droot(amount); }