Three weakly related fixes to number handling after the univalue
switch. These came to the surface while troubleshooting #6443.
Make ValueFromAmount always return 8 decimals
This is the format that was always returned to JSON clients. The difference was not noticed before, because VREAL values are post-processed by univalue.
By implementing the functionality directly it breaks the dependency of rpcserver on utilmoneystr. FormatMoney is now only used for debugging purposes.
To test, port over the formatting tests from util_tests.cpp to rpc_tests.cpp.
univalue: Avoid unnecessary roundtrip through double for numbers
JSON makes no distinction between numbers and reals, and our code doesn’t need to do so either.
This removes VREAL, as well as its specific post-processing in UniValue::write
. Non-monetary amounts do not need to be forcibly formatted with 8 decimals, so the extra roundtrip was unnecessary (and potentially loses precision).
util: use locale-independent parsing in ParseDouble
Use locale-indepent C++ based parsing instead of C’s strtod, which checks for different input based on the user’s locale. Fixes #6443.