Merge pull request #214 from samlanning/is-float
Various improvements to float parsing
This commit is contained in:
commit
bff9ea2c16
@ -488,7 +488,7 @@ Amount.parse = function parse(value, exp, num) {
|
|||||||
Amount.parseUnsafe = function parseUnsafe(value, exp, num) {
|
Amount.parseUnsafe = function parseUnsafe(value, exp, num) {
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
assert(util.isFloat(value), 'Non-BTC value for conversion.');
|
assert(util.isFloat(value), 'Non-BTC value for conversion.');
|
||||||
value = parseFloat(value, 10);
|
value = parseFloat(value);
|
||||||
} else {
|
} else {
|
||||||
assert(util.isNumber(value), 'Non-BTC value for conversion.');
|
assert(util.isNumber(value), 'Non-BTC value for conversion.');
|
||||||
assert(num, 'Cannot parse number.');
|
assert(num, 'Cannot parse number.');
|
||||||
|
|||||||
@ -392,6 +392,11 @@ util.isHex256 = function isHex256(hash) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether a string qualifies as a float.
|
* Test whether a string qualifies as a float.
|
||||||
|
*
|
||||||
|
* This is stricter than checking if the result of parseFloat() is NaN
|
||||||
|
* as, e.g. parseFloat successfully parses the string '1.2.3' as 1.2, and
|
||||||
|
* we also check that the value is a string.
|
||||||
|
*
|
||||||
* @param {String?} value
|
* @param {String?} value
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user