Skip to content

Commit

Permalink
fix: correct rounding to N decimal places, incorrectly was N-1
Browse files Browse the repository at this point in the history
  • Loading branch information
jdbruijn committed Mar 20, 2023
1 parent a14643c commit dc62974
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/exporter/measurement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type P1Meter from '../p1-meter/api.js';
import Exporter from './exporter.js';

function round(value: number, decimalPlaces: number): number {
const multipler = 10 ** Math.max(0, decimalPlaces - 1);
return Math.round((value + Number.EPSILON) * multipler) / multipler;
const factor = 10 ** Math.max(0, decimalPlaces);
return Math.round((value + Number.EPSILON) * factor) / factor;
}

export default class Measurement extends Exporter {
Expand Down

0 comments on commit dc62974

Please sign in to comment.