简体   繁体   中英

Qt double from JSON precision

I receive a JSON Array from a server which looks like: [0.00015099, 1, -672.41163] These values are orderbook entries. If I try to parse all values as double, my price differs slightly from the price in the JSON array. It is clear for me, that this happens because of the double conversion, but how to program around some crazy stuff like this? Need these values also for calculation, compares etc. I am using Qt5 and C++.

Any hint?

Well, you should use some Decimal type if you want to deal with money to be on a safe side. Unfortunately, Qt does not have decimal type for some reason. So, you may end up with some rounding rules/conventions if you have no other choice . Otherwise you'd better to implement your own implementation or use some existing solution like qdecimal .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM