As mentioned in bitshares/bitshares-ui#3545 (comment), the function to_long() in SerializerValidation.js may return unexpected result if the input is a float with decimals (E.G. 12.999999999999998). Code:
|
to_long(value, field_name = "", unsigned = false) { |
|
if (this.is_empty(value)) { |
|
return value; |
|
} |
|
if (Long.isLong(value)) { |
|
return value; |
|
} |
|
|
|
this.no_overflow64(value, field_name, unsigned); |
|
if (typeof value === "number") { |
|
value = "" + value; |
|
} |
|
return Long.fromString(value, unsigned); |
|
}, |
> parseFloat("0.00013")*100000
12.999999999999998
> Long.fromString(""+parseFloat("0.00013")*100000)
Long { low: 1150981118, high: 30, unsigned: false }
> Long.fromString(""+parseFloat("0.00013")*100000).toString()
129999999998
To fix this, IMHO, as a library, we shouldn't change user input, but we should require the input to be valid.
As mentioned in bitshares/bitshares-ui#3545 (comment), the function
to_long()inSerializerValidation.jsmay return unexpected result if the input is afloatwith decimals (E.G.12.999999999999998). Code:bitsharesjs/lib/serializer/src/SerializerValidation.js
Lines 103 to 116 in c962b80
To fix this, IMHO, as a library, we shouldn't change user input, but we should require the input to be valid.