diff --git a/api.ts b/api.ts index dea54c7..46e642c 100644 --- a/api.ts +++ b/api.ts @@ -52,7 +52,7 @@ router.get('/dseg_price/:billcode/:shipcode/:stlc/:dseg/:qty', async (ctx) => { const { billcode, shipcode, stlc, dseg, qty } = ctx.params; const result = await client.queryObject({args: [billcode, shipcode, stlc, dseg, qty], text: query_dseg} ); const ag = apply_guidance(result.rows[0]["doc"]); - ctx.response.body = ag.guidance.FinalReason; + ctx.response.body = ag.guidance.finalPrice.Snapped; }); app.use(router.routes()); diff --git a/apply_guidance.ts b/apply_guidance.ts index 456ab45..4cfe252 100644 --- a/apply_guidance.ts +++ b/apply_guidance.ts @@ -41,7 +41,11 @@ export function apply_guidance(doc: any) { } function pp(value) { - return (value * 1000).toFixed(2); + // Multiplies by 1000 and rounds to the nearest 2 decimals + var result = Math.round(value * 1000 * 100) / 100; + + // Converts the number to a string with commas for thousand separators + return result.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2}); } // --------------------extract incoming data------------------------------------------------------ @@ -84,9 +88,9 @@ export function apply_guidance(doc: any) { let custSeason = earlyCustSeason; let custReason = bridgePremium ? `${custSeason} (similar ${altHist} price ${pp(earlyCustPrice)} x ${bridgePremium} = ${pp(bridgedPrice)})${custAddReason}` - : `${custSeason} + price ${pp(custPrice)}${custAddReason}`; + : `${custSeason} price ${pp(custPrice)}${custAddReason}`; let markPrice = earlyMarkPrice * (1 + markAdder); - let markReason = `${earlyMarkSeason} ASP + ${pp(earlyMarkPrice)}${markAddReason}`; + let markReason = `${earlyMarkSeason} ASP ${pp(earlyMarkPrice)}${markAddReason}`; let targPrice = targetPrice * (1 + markAdder); let targReason = `Target price ${pp(targetPrice)}${markAddReason}`; let listPrice = listUSD;