Skip to content

Commit

Permalink
MadNumericField: Fix floating point issue when not rounding any value…
Browse files Browse the repository at this point in the history
…s (2.3*100 = 229.999 and is displayed as 2.29)
  • Loading branch information
Laess3r committed Aug 7, 2024
1 parent c382cd0 commit d152b58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ The versioning of material-addons is based on the Angular version. The Angular v
_Hint: Changes marked as **visible change** directly affect your application during version upgrade. **Breaking**
requires your attention during upgrade._

- **18.0.3**: Fix MadNumericField: Fix floating point issue when not rounding any values (2.3*100 = 229.999 and is displayed as 2.29)
- **18.0.2**: data table fix for onExpand call
- **18.0.1**: Prettier fixes, alert component fix
- **18.0.0**: Upgrade to Angular 18
- **17.4.5**: Fix MadNumericField: Fix floating point issue when not rounding any values (2.3*100 = 229.999 and is displayed as 2.29)
- **17.4.4**: bugfix for data table display data
- **17.4.3**: Minor improvements for data table, readonly form fields and sidebar
- **17.4.2**: Moved text-overflow and ellipsis logic from readonly-form-field-wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,14 @@ export class NumericFieldDirective implements OnInit, OnDestroy, AfterViewChecke
}
}


private roundOrTruncate(value: number): number {
const method = this.roundValue ? 'round' : value < 0 ? 'ceil' : 'floor';
return Math[method](value * Math.pow(10, this.decimalPlaces)) / Math.pow(10, this.decimalPlaces);
if (this.roundValue) {
return Math.round(value * Math.pow(10, this.decimalPlaces)) / Math.pow(10, this.decimalPlaces);
}

const method = value < 0 ? "ceil" : "floor";

return Math[method](+(value * Math.pow(10, this.decimalPlaces)).toFixed(this.decimalPlaces)) / Math.pow(10, this.decimalPlaces);
}
}

0 comments on commit d152b58

Please sign in to comment.