utils.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * DevExtreme (localization/utils.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. Object.defineProperty(exports, "__esModule", {
  11. value: true
  12. });
  13. exports.toFixed = void 0;
  14. var _math = require("../core/utils/math");
  15. var DECIMAL_BASE = 10;
  16. function roundByAbs(value) {
  17. var valueSign = (0, _math.sign)(value);
  18. return valueSign * Math.round(Math.abs(value))
  19. }
  20. function adjustValue(value, precision) {
  21. var precisionMultiplier = Math.pow(DECIMAL_BASE, precision);
  22. var roundMultiplier = precisionMultiplier * DECIMAL_BASE;
  23. var intermediateValue = value * roundMultiplier / DECIMAL_BASE;
  24. return roundByAbs(intermediateValue) / precisionMultiplier
  25. }
  26. function toFixed(value, precision) {
  27. var valuePrecision = precision || 0;
  28. var adjustedValue = valuePrecision > 0 ? adjustValue.apply(void 0, arguments) : value;
  29. return adjustedValue.toFixed(valuePrecision)
  30. }
  31. exports.toFixed = toFixed;