RPC: reals as strings #247

issue mikegogulski opened this issue on May 20, 2011
  1. mikegogulski commented at 8:48 PM on May 20, 2011: none

    I'm using Jan-Klaas Kollhof's JSON-RPC implementation for Python.

    My app tracks amounts using the Decimal class, in order to avoid floating point representation errors.

    I should be able to do:

    '{"params":["15DTr7vBr9VA52cEh2k7ywPeHL9WVFadwk","3.22","comment"],"method":"sendtoaddress","id":"1305920532.77"}'

    but bitcoind returns a "got string, expected real" error because "3.22" is quoted.

    If I convert the value to a float, it goes like this:

    '{"params":["15DTr7vBr9VA52cEh2k7ywPeHL9WVFadwk",3.219999999,"comment"],"method":"sendtoaddress","id":"1305920532.77"}'

    which is a mess.

    Right now, I'm hacking around this by altering the json string after building it, using the value as a string and then stripping the double quotes to change its JSON representation to a real.

    Is there a reason why a string value can't be cast into a real inside bitcoind?

  2. gavinandresen commented at 3:59 PM on August 9, 2011: contributor

    Not sure if you saw this in the pull request: If you want all of your json strings to look pretty, use the latest version of simplejson that fully supports Decimal JSON values; e.g.

    import decimal import simplejson simplejson.dumps(decimal.Decimal('10000000.000000009'), use_decimal=True) '10000000.000000009'

    I don't like the idea of automatically casting strings to numbers in the RPC interface, it just means more lines of code to fix a problem that a) isn't a problem (3.219999999 looks ugly but behaves exactly the same as 3.22) and b) can be fixed by using the latest version of simplejson.

  3. gavinandresen closed this on Aug 9, 2011

  4. zathras-crypto referenced this in commit ad34cd0330 on Dec 18, 2014
  5. sipa referenced this in commit 0350c7e4b8 on Jul 28, 2015
  6. sipa referenced this in commit 7863d105ea on Aug 4, 2015
  7. sipa referenced this in commit 780d5b3c7b on Aug 23, 2015
  8. TheBlueMatt referenced this in commit a671356e1f on Oct 20, 2015
  9. sipa referenced this in commit 9177950c74 on Oct 21, 2015
  10. sipa referenced this in commit f4787d1caf on Oct 21, 2015
  11. sipa referenced this in commit 6557a8cd46 on Oct 26, 2015
  12. sipa referenced this in commit ea06490d14 on Oct 27, 2015
  13. sipa referenced this in commit 003bb87153 on Nov 5, 2015
  14. sipa referenced this in commit bfd83199c3 on Nov 11, 2015
  15. sipa referenced this in commit b437ea7ec9 on Nov 12, 2015
  16. sipa referenced this in commit 1d84107924 on Nov 12, 2015
  17. rebroad referenced this in commit 40ead34fbe on Dec 7, 2016
  18. deadalnix referenced this in commit 91eb0da155 on Jan 19, 2017
  19. deadalnix referenced this in commit bd4e214561 on May 10, 2017
  20. lateminer referenced this in commit c2399bc8f8 on Dec 9, 2017
  21. classesjack referenced this in commit 0809d46f6b on Jan 2, 2018
  22. attilaaf referenced this in commit 52525774c6 on Jan 13, 2020
  23. rajarshimaitra referenced this in commit 6b3adc63ad on Aug 5, 2021
  24. DrahtBot locked this on Sep 8, 2021
  25. hebasto referenced this in commit 9013f23b0a on Sep 30, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-20 03:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me