[as] feat: 부동소수점 처리

This commit is contained in:
2026-08-25 10:31:40 +09:00
parent a4c14433cd
commit 7baebf2cbc
8 changed files with 50 additions and 23 deletions
@@ -1,4 +1,4 @@
import type { CostItemDef } from "@/widgets/pbadms-sprt/lib/business-cost-form-utils";
import { type CostItemDef, roundAmount } from "@/widgets/pbadms-sprt";
export interface BizCstMatrixItem {
planStpNo: number;
@@ -45,9 +45,11 @@ function recalculateBizCstMatrix(
if (!item.readonly || !item.children) continue;
for (const planStpNo of PLAN_STEPS) {
const childSum = item.children.reduce(
(sum, childCode) => sum + getAmt(next, childCode, planStpNo),
0,
const childSum = roundAmount(
item.children.reduce(
(sum, childCode) => sum + getAmt(next, childCode, planStpNo),
0,
),
);
const current = getAmt(next, item.code, planStpNo);
if (current !== childSum) {
@@ -1,4 +1,4 @@
import type { CostItemDef } from "@/widgets/pbadms-sprt/lib/business-cost-form-utils";
import { type CostItemDef, roundAmount } from "@/widgets/pbadms-sprt";
import { type BizCstMatrixItem,getAmt, PLAN_STEPS } from "./biz-cst-matrix-utils";
@@ -31,11 +31,11 @@ function getBizCstStepTotal(
}
function sumFnrsCstLeaf(item: FnrsCstItem): number {
return (
return roundAmount(
(item.gvexpAmt ?? 0) +
(item.lcexpAmt ?? 0) +
(item.orgprBdchgAmt ?? 0) +
(item.etcAmt ?? 0)
(item.lcexpAmt ?? 0) +
(item.orgprBdchgAmt ?? 0) +
(item.etcAmt ?? 0),
);
}
@@ -55,7 +55,7 @@ function calcFnrsCstRemaining(
const bizTotal = getBizCstStepTotal(bizCstList, costItems, planStpNo);
const fnrsItem = fnrsCstList.find((item) => item.planStpNo === planStpNo);
const sharTotal = fnrsItem ? sumFnrsCstLeaf(fnrsItem) : 0;
return { planStpNo, remaining: bizTotal - sharTotal };
return { planStpNo, remaining: roundAmount(bizTotal - sharTotal) };
});
}
@@ -154,8 +154,7 @@ function FnrsCstFormSection() {
<TableCell key={planStpNo}>
<Field>
<Input
type="text"
inputMode="decimal"
type="number"
className={cn("text-right", row.readonly && "bg-muted")}
readOnly={row.readonly}
disabled={row.readonly}
+1 -1
View File
@@ -30,7 +30,7 @@ export {
toFnrsSharSaveList,
validateBizCstSharBalance,
} from "./lib/fnrs-shar-form-utils";
export { calcDiffPercent, fmtNumber, indentPx } from "./lib/format-utils";
export { calcDiffPercent, fmtNumber, indentPx, roundAmount } from "./lib/format-utils";
export { AttachmentsFormSection } from "./ui/attachments-form-section";
export { AttachmentsViewSection } from "./ui/attachments-view-section";
export { BusinessCostFormSection } from "./ui/business-cost-form-section";
@@ -1,5 +1,7 @@
import type { AcntgSeMngTreeDto } from "@/entities/acntg";
import { roundAmount } from "./format-utils";
export interface CostItemDef {
code: string;
label: string;
@@ -29,7 +31,11 @@ function sumChildAmounts(list: BizCstListItem[], childCodes: string[]) {
}
});
return { bscPlanAmt, bgtRfltAmt, tstmDesignAmt };
return {
bscPlanAmt: roundAmount(bscPlanAmt),
bgtRfltAmt: roundAmount(bgtRfltAmt),
tstmDesignAmt: roundAmount(tstmDesignAmt),
};
}
export function buildAcntgCostItems(tree: AcntgSeMngTreeDto[]): CostItemDef[] {
@@ -1,5 +1,7 @@
import type { CnstpSeMngTreeDto } from "@/entities/cnstp";
import { roundAmount } from "./format-utils";
export interface ScaleItemDef {
code: string;
label: string;
@@ -30,13 +32,17 @@ function sumChildScale(list: BzScaleListItem[], childCodes: string[]) {
}
});
return { bscPl, budgetReflct, thtiDsgn };
return {
bscPl: roundAmount(bscPl),
budgetReflct: roundAmount(budgetReflct),
thtiDsgn: roundAmount(thtiDsgn),
};
}
function withDiff(item: BzScaleListItem): BzScaleListItem {
const budgetReflct = item.budgetReflct || 0;
const thtiDsgn = item.thtiDsgn || 0;
return { ...item, diff: thtiDsgn - budgetReflct };
return { ...item, diff: roundAmount(thtiDsgn - budgetReflct) };
}
export function buildCnstpScaleItems(tree: CnstpSeMngTreeDto[]): ScaleItemDef[] {
@@ -2,6 +2,7 @@ import type { FnrsSharItem } from "@/entities/fnrs-cnsltn";
import type { FnrsSharBizCstTreeDto, FnrsSharSeMngTreeDto } from "@/entities/fnrs-shar-se";
import type { BizCstListItem, CostItemDef } from "./business-cost-form-utils";
import { roundAmount } from "./format-utils";
export interface FnrsSharItemDef {
code: string;
@@ -78,7 +79,10 @@ function sumChildSharAmounts(list: FnrsSharListItem[], childCodes: string[]) {
chgRqtAmt += child.chgRqtAmt || 0;
});
return { exstnAmt, chgRqtAmt };
return {
exstnAmt: roundAmount(exstnAmt),
chgRqtAmt: roundAmount(chgRqtAmt),
};
}
export function recalculateFnrsSharTotals(
@@ -103,7 +107,7 @@ export function recalculateFnrsSharTotals(
...current,
exstnAmt,
chgRqtAmt,
ajmtAmt: exstnAmt - chgRqtAmt,
ajmtAmt: roundAmount(exstnAmt - chgRqtAmt),
};
hasChanges = true;
}
@@ -158,7 +162,10 @@ export function sumFnrsSharLeafAmounts(
chgRqtAmt += row.chgRqtAmt || 0;
});
return { exstnAmt, chgRqtAmt };
return {
exstnAmt: roundAmount(exstnAmt),
chgRqtAmt: roundAmount(chgRqtAmt),
};
}
export function calcBizCstSharRemaining(
@@ -171,8 +178,8 @@ export function calcBizCstSharRemaining(
const leafSum = sumFnrsSharLeafAmounts(sharList, sharItems);
return {
exstnRemaining: bizCstTotal.bscPlanAmt - leafSum.exstnAmt,
chgRqtRemaining: bizCstTotal.tstmDesignAmt - leafSum.chgRqtAmt,
exstnRemaining: roundAmount(bizCstTotal.bscPlanAmt - leafSum.exstnAmt),
chgRqtRemaining: roundAmount(bizCstTotal.tstmDesignAmt - leafSum.chgRqtAmt),
};
}
@@ -201,7 +208,7 @@ export function toFnrsSharSaveList(list: FnrsSharListItem[]): FnrsSharItem[] {
fnrsSharSeCd: row.fnrsSharSeCd,
exstnAmt: row.exstnAmt || 0,
chgRqtAmt: row.chgRqtAmt || 0,
ajmtAmt: (row.exstnAmt || 0) - (row.chgRqtAmt || 0),
ajmtAmt: roundAmount((row.exstnAmt || 0) - (row.chgRqtAmt || 0)),
rmrkCn: row.rmrkCn,
}));
}
@@ -239,7 +246,7 @@ export function mapFnrsSharDetToFormList(tree: FnrsSharBizCstTreeDto[]): FnrsSha
fnrsSharSeCd: item.code,
exstnAmt,
chgRqtAmt,
ajmtAmt: exstnAmt - chgRqtAmt,
ajmtAmt: roundAmount(exstnAmt - chgRqtAmt),
rmrkCn: node?.rmrkCn ?? "",
};
});
@@ -18,6 +18,13 @@ export function indentPx(indNm: string | undefined): number {
return (spaces / 4) * 16;
}
const AMOUNT_DECIMAL_PLACES = 2;
export function roundAmount(value: number): number {
const factor = 10 ** AMOUNT_DECIMAL_PLACES;
return Math.round((value + Number.EPSILON) * factor) / factor;
}
export function calcDiffPercent(diff: number, baseline: number): string {
if (baseline === 0) return "-";
return `${Math.round((diff / baseline) * 100)}%`;