jaystack / jaydata

Notice: this library isn't maintained anymore
http://jaydata.org
GNU General Public License v2.0
352 stars 95 forks source link

$data.Decimal Converter should support scientific notation numbers #203

Open adriankb opened 9 years ago

adriankb commented 9 years ago

Using JayData 1.3.4

$data.Decimal converter fails when the string value is a scientific notation number.

i.e. 8.90170295494883e-05

fails the check

if (!/^-?([0-9]+(.[0-9]+)?|Infinity)$/.test(value)) throw 0;

to check for a scientific notation number you can use

/[+-]?(?:0|[1-9]\d)(?:.\d)?(?:[eE][+-]?\d+)?/.test(value)

and then to convert it use

floatVal = Number(value); if (isNaN(floatVal)) { throw 0; }

jaydata commented 9 years ago

Thanks, it'll get into the next update - which is in about two weeks