Skip to content

Commit

Permalink
handle null/undefined/NaN in number computations
Browse files Browse the repository at this point in the history
  • Loading branch information
mcsdodo committed May 11, 2023
1 parent c210d18 commit 2367f3a
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions sygic-geotab-utils/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class DimensionsModel {

// numbers are stored with 5 decimals. Displayed and used when parsing inputs with 2 decimals.
let roundTo2Decimals = (number) => {
if (number !== undefined)
if (number)
return Math.round(number * 100) / 100;
}

Expand Down Expand Up @@ -239,24 +239,24 @@ const constants = {
};

export let Dimensions = {
convertWeightToMetric: (weight, rounding = 1e5) => {
if (weight !== undefined)
return Math.round(weight / constants.poundsInKilos * rounding) / rounding;
convertWeightToMetric: (number, rounding = 1e5) => {
if (number)
return Math.round(number / constants.poundsInKilos * rounding) / rounding;
},

convertDimensionToMetric: (dimension, rounding = 1e5) => {
if (dimension !== undefined)
return Math.round(dimension / constants.feetInMilimeters * rounding) / rounding;
convertDimensionToMetric: (number, rounding = 1e5) => {
if (number)
return Math.round(number / constants.feetInMilimeters * rounding) / rounding;
},

convertWeightToImperial: (weight, rounding = 1e5) => {
if (weight !== undefined)
return Math.round(weight * constants.poundsInKilos * rounding) / rounding;
convertWeightToImperial: (number, rounding = 1e5) => {
if (number)
return Math.round(number * constants.poundsInKilos * rounding) / rounding;
},

convertDimensionToImperial: (dimension, rounding = 1e5) => {
if (dimension !== undefined)
return Math.round(dimension * constants.feetInMilimeters * rounding) / rounding;
convertDimensionToImperial: (number, rounding = 1e5) => {
if (number)
return Math.round(number * constants.feetInMilimeters * rounding) / rounding;
},

getInputValues: (parentElement) => {
Expand Down

0 comments on commit 2367f3a

Please sign in to comment.