[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 -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)}%`;