dynamodb-toolbox icon indicating copy to clipboard operation
dynamodb-toolbox copied to clipboard

Strings containing floats ending in trailing zeros are unable to be coerced to floats.

Open michael-wolfenden opened this issue 3 years ago • 1 comments

Bug Report

Strings containing floats ending in trailing zeros are unable to be coerced to floats.

Instead a 'attr' must be of type number error is raised.

For example

validateTypes(DocumentClient)({ type: 'number' },'attr', '1.00')

This issue stems from the fact that parseFloat strips trailing zeros so the string representation ('1.00') not longer matches the parseFloat representaton ('1') causing the error to be thrown.

https://github.com/jeremydaly/dynamodb-toolbox/blob/4cbb92a89e156cd7524dae36d1921ea6f7f02503/lib/validateTypes.js#L31

michael-wolfenden avatar Aug 10 '20 05:08 michael-wolfenden

would this be an ok change for this? if so I'll make it and submit a PR..

value == value/1

this works for things I've tried.. "1" == "1"/1 and "1.00" == "1.00"/1 will both return true.. "abdhd1.00" == "abdhd1.00"/1 will return false. null == null/1 will return false as well..

gpinkham avatar Sep 12 '20 00:09 gpinkham

@gpinkham true == true/1 so this is not good enough.

igalklebanov avatar Nov 12 '22 11:11 igalklebanov