Solving the problem of the round of the whole function in Delphi

Source: Internet
Author: User

There is a bug in the round function in Delphi
Once the parameter is a number such as xxx.5
If XXX is odd then it will Round up
If XXX is an even number then it will Round down
For example Round (17.5) =18
But Round (12.5) =12
The following function corrects this Bug, but it's temporary.
Execution Doround (12.5) results are 13 correct

[Delphi]View PlainCopy
  1. function Doround (value:extended): Int64;
  2. procedure SET8087CW (Newcw:word);
  3. ASM
  4. MOV Default8087cw,ax
  5. Fnclex
  6. FLDCW DEFAULT8087CW
  7. end;
  8. Const
  9. ROUNDUPCW = $1b32;
  10. Var
  11. Oldcw:word;
  12. Begin
  13. OLDCW: = DEFAULT8087CW;
  14. Try
  15. SET8087CW (ROUNDUPCW);
  16. Result: = Round (Value);
  17. finally
  18. SET8087CW (OLDCW);
  19. end;
  20. End

http://blog.csdn.net/chaijunkun/article/details/5519153

Solving the problem of the round of the whole function in Delphi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.