Files
Aislo/M01_MasterData/M01_MasterData_UI_Logic_Money.ts
T

20 lines
1.0 KiB
TypeScript

/* =============================================================================
* M01_MasterData_UI_Logic_Money.ts
* 돈 모양 한 벌 — 원 단위 정수(반올림). 단가·금액·소계·계 자리만 씀 · 수량·비율은 `formatNumber` 그대로
* ========================================================================== */
import { formatNumber } from "./M01_MasterData_UI_Logic_Edit";
export const formatMoney = (value: unknown): string =>
typeof value === "number"
? value.toLocaleString("ko-KR", { maximumFractionDigits: 0 })
: formatNumber(value);
/** 단가 모양 — 정수로 보이되 200 원 미만은 반올림 오차가 커서 소수 넷째 자리·유효숫자 4 자리 중 많은 쪽(뒤 0 뗌) */
export const formatPrice = (value: unknown): string =>
typeof value === "number" && value !== 0 && Math.abs(value) < 200
? value.toLocaleString("ko-KR", {
maximumFractionDigits: Math.max(4, 3 - Math.floor(Math.log10(Math.abs(value)))),
})
: formatMoney(value);