WTF- Client doesn't display more than two decimal places. #301

issue sdlkfjdslkfj opened this issue on June 6, 2011
  1. sdlkfjdslkfj commented at 2:44 AM on June 6, 2011: none

    The problem is in the FormatMoney function, in util.cpp. This comment includes a fixed version, which requires two support functions, which are also included:

    int64
    last_digit(int64 n) {
        int64 m = n / (int64)10;
    
        m *= (int64)10;
        return n - m;
    }
    
    char
    todigit(int64 n) {
        static char digits[] = "0123456789";
        return digits[n];
    }
    
    string
    FormatMoney(int64 n, bool fPlus)
    {
        string str;
        bool was_negative = n<0;
        bool omit_digit = true;     // Omit trailing zeros.
        size_t ix=0;
    
        if(n == 0) {
            str.insert(0,1,'0');
            return str;
        }
        if(n < 0) {
            n = -n;
        }
        // Process the number from right to left.
        for(ix=0; n || ix<8; ix++) {
            int64 next = last_digit(n);
            n /= (int64)10;
            if(next || ix>=8) omit_digit=false;
            if(!omit_digit) {
                str.insert(0,1,todigit(next));
                if(ix == 7) str.insert(0,1,'.');
            }
        }
    
        if(was_negative) str.insert(0,1,'-');
        else if(fPlus) str.insert(0,1,'+');
        return str;
    }
    
  2. gavinandresen commented at 11:13 AM on June 6, 2011: contributor

    Can you give me an amount that the current FormatMoney doesn't display properly?

    It is currently written to:

    • use printf() to create a string like "1.00000000"
    • trim all but the last two trailing zeroes, so "1.00000000" becomes "1.00" and "1.00001000" becomes "1.00001"
  3. gavinandresen closed this on Aug 9, 2011

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

    Closed. Will re-open if given an amount that the current FormatMoney does not handle properly.

  5. sipa referenced this in commit 9177950c74 on Oct 21, 2015
  6. sipa referenced this in commit f4787d1caf on Oct 21, 2015
  7. sipa referenced this in commit 6557a8cd46 on Oct 26, 2015
  8. sipa referenced this in commit ea06490d14 on Oct 27, 2015
  9. sipa referenced this in commit 003bb87153 on Nov 5, 2015
  10. sipa referenced this in commit bfd83199c3 on Nov 11, 2015
  11. sipa referenced this in commit b437ea7ec9 on Nov 12, 2015
  12. sipa referenced this in commit 1d84107924 on Nov 12, 2015
  13. jtimon referenced this in commit 91ee21c024 on Mar 11, 2016
  14. rebroad referenced this in commit 40ead34fbe on Dec 7, 2016
  15. deadalnix referenced this in commit c822693eff on Jan 19, 2017
  16. classesjack referenced this in commit c9be6fbf90 on Jan 2, 2018
  17. lateminer referenced this in commit e9834edfd0 on Oct 16, 2019
  18. cryptapus referenced this in commit 330a200066 on May 3, 2021
  19. rajarshimaitra referenced this in commit 32684a1462 on Aug 5, 2021
  20. bitcoin locked this on Sep 8, 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-05-20 06:56 UTC