Add a condition for parsing zero from string when not denominated.#3346
Conversation
Pull Request Test Coverage Report for Build 10833023984Details
💛 - Coveralls |
9c9a7d4 to
8ed3d0b
Compare
Kixunil
left a comment
There was a problem hiding this comment.
Please do it as I recommended in the issue (try to parse it with denomination and if it fails also try the usual parsing function and check for zero). The way you wrote it makes the code possibly inconsistent and I suspect it'd break for inputs like 0.00000000000000001.
8ed3d0b to
8d65dc7
Compare
I'll take a look again. It seemed overly complicated to do it that way, but maybe I overlooked something. |
5b7e74d to
fb92ce7
Compare
|
@Kixunil I've updated it as you suggested. It's a bit more verbose but I understand wanting consistency. I'm kinda surprised not just using standard float parsing under the hood, although I imagine there is a reason.. |
699b055 to
4ff3f4b
Compare
|
It looks like alloc is now required unless I'm missing something. |
The reason is floats are absolutely wrong for financial applications because they are not precise enough. There's a ton about this on the Internet, I'm sure you'll find more information easily if you need it.
|
4ff3f4b to
627bf3f
Compare
Hmm that's interesting. I read that financial applications usually use decimal notation with fixed precision vs a float where the precision "floats". I take it that means the rust library
The source string "0" has " sat" concatenated to the end so that it doesn't fail to parse. somehow there needs to be an allocation so that the source string can resize to hold the denomination which is why I think it needs alloc, unless Im mistaken. |
|
Also this needs documenting how |
627bf3f to
c8ad413
Compare
c8ad413 to
894f82e
Compare
I would have thought there be a compile error about |
On topic, |
| let _a = SignedAmount::from_str("0").unwrap(); | ||
| let _a = SignedAmount::from_str("0.0").unwrap(); | ||
| let _a = SignedAmount::from_str("00.0").unwrap(); | ||
| } |
There was a problem hiding this comment.
A test confirming that 0.00 parses would be nice too.
There was a problem hiding this comment.
can just do in another comment since this one is already acked. This is also something that could just be part of a proptest given arbitrary dot placement which is probably more effective.
There was a problem hiding this comment.
Good idea turning it to proptest, but I'd like to see also various lengths not just dot placement being changed.
f5cae1c Comment from_str methods (yancy) Pull request description: Follow up from #3346 ACKs for top commit: tcharding: ACK f5cae1c apoelstra: ACK f5cae1c successfully ran local tests Tree-SHA512: 2b95381e5281754e2b3a49aa8dfaac5742c244970fb54f68024dc23b61a74955ae95b9a0e7ae848095ac0686df5faf93faf7de3371b2f341b108cc10e5d4a9cd
closes #3307