Skip to content

Commit

Permalink
refactor(scraper): use constant amount of digits for rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Apr 20, 2024
1 parent c55ce7c commit 995bddc
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/content/quoteRecords/_scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { roundTo, safeParseFloat } from "../../utils/number";

const SOURCE_URL = "https://www.mnb.hu/Root/ExchangeRate/arfolyam.xlsx";
const QUOTE_CURRENCY = "HUF";
const DEFAULT_FRACTION_DIGITS = 2;
const MAX_MINOR_UNIT = 8;

const response = await fetch(
process.argv.includes("--full", 1)
Expand Down Expand Up @@ -65,10 +65,7 @@ for (const rateRow of rateRows) {
if (offsetRate != null) {
const unit = unitByCurrency.get(key);
if (unit != null) {
const rate = roundTo(
offsetRate / unit,
DEFAULT_FRACTION_DIGITS + Math.ceil(Math.log10(unit)),
);
const rate = roundTo(offsetRate / unit, MAX_MINOR_UNIT);

// Validation
if (rate > 0) {
Expand Down

0 comments on commit 995bddc

Please sign in to comment.