bitshares / bitshares/bitsharesjs

Function `to_long()` returns unexpected value when input is float with decimals

Open
#99 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
96
Forks
151
Avg merge
7h 39m
Merged PRs (30d)
2

Description

As mentioned in https://github.com/bitshares/bitshares-ui/issues/3545#issuecomment-1236207285, the function `to_long()` in `SerializerValidation.js` may return unexpected result if the input is a `float` with decimals (E.G. `12.999999999999998`). Code: https://github.com/bitshares/bitsharesjs/blob/c962b80f625d550573e847e6f1466524109fd3ea/lib/serializer/src/SerializerValidation.js#L103-L116

```
> 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.