Results 1 to 10 of 10

Thread: Banker's rounding

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    76
    Thanked 37 Times in 32 Posts

    Default Re: Banker's rounding

    OMG !!

    I am getting 8.93 on g++ 3.4.4 (linux ) and g++ (GCC) 3.4.2 (mingw-special) Windows
    We can't solve problems by using the same kind of thinking we used when we created them

  2. #2
    Join Date
    Jun 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Banker's rounding

    got me puzzled..

    g++ -v
    Using built-in specs.
    Target: x86_64-redhat-linux
    Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-cpu=generic --host=x86_64-redhat-linux
    Thread model: posix
    gcc version 4.1.2 20070502 (Red Hat 4.1.2-12)

    I am using fedora core 7 x86_64

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Banker's rounding

    .5 might actually be .49999999999999 on 64b so after flooring this will be 0 Try changing the datatype (for instance to float).

    BTW. For banking (or similar) you should use high precision math, for example one of these:
    http://www.tc.umn.edu/~ringx004/article-main.html
    http://www.nongnu.org/hpalib/
    http://gmplib.org/

  4. The following user says thank you to wysota for this useful post:

    sunil.thaha (25th June 2007)

  5. #4
    Join Date
    Jun 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Banker's rounding

    Quote Originally Posted by wysota View Post
    .5 might actually be .49999999999999 on 64b so after flooring this will be 0 Try changing the datatype (for instance to float).
    You are right there - have been programming so long in Delphi using their Currency type that I forgot that doubles (and floats) can be a bit inaccurate, I changed the function parameter and return value to floats and i get a correct result.
    Quote Originally Posted by wysota View Post
    BTW. For banking (or similar) you should use high precision math, for example one of these:
    http://www.tc.umn.edu/~ringx004/article-main.html
    http://www.nongnu.org/hpalib/
    http://gmplib.org/
    I will have a look at these.. really need something similar to the pascal currency type...

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Banker's rounding

    Quote Originally Posted by matheww View Post
    really need something similar to the pascal currency type...
    See this: http://quantlib.org/

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.