Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6662225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:22:02+00:00 2026-05-26T02:22:02+00:00

The problem is simple and strange! I wrote a program in Delphi and used

  • 0

The problem is simple and strange!
I wrote a program in Delphi and used roundto function. In one computer 1.5 is rounded to 2 and in another computer it is rounded to 1.
How could this happen?

P.S: Code——> Roundto(1.5, 0)

P.S 2: It seems more information is needed so I post more exact detail. I wrote a program. They entered two number: a=7231.76 b=3556.71
Now they can enter a third number c if c >= a – b but the exact formation in my code is

`roundto(c, -1) >= roundto(a, -1) - roundto(b, -1)`
`roundto(a, -1) = 7231.8`
`roundto(b, -1) = 3556.7`

so

`roundto(a, -1) - roundto(b, -1) = 3675.1`

they entered

`c = 3675.05`

I traced the program. In one computer it says round(c, -1) = 3675.1 and in another computer it says round(c, -1) = 3675.0

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:22:03+00:00Added an answer on May 26, 2026 at 2:22 am

    I would say you encountered the “banker’s rounding” problem, and you posted the wrong data 🙂
    Delphi RoundTo implements the banker’s rounding: Odd numbers that end in .5 are rounded upwards, that’s the traditional behavior, but… Even numbers that end in .5 are rounded downwards!
    So 1.5 is rounded to 2.0, but 2.5 is rounded to 2.0 (link to a reference of RoundTo)

    Second possibility: http://www.merlyn.demon.co.uk/pas-chop.htm#DRT there is a bug in certain versions of Delphi. Do you have the same version of Delphi in all the machines?

    Third possibility: you are speaking of floating points! They aren’t exact numbers! Adding and subtracting them creates a microworld of decimals normally invisible 0.1 + 0.2 != 0.3!! Perhaps what you see as .5 isn’t exactly .5 but is .49999999 or .500000001. If you want to check it, step into the debugger and check if c = 3675.05 (the logical expression) is true or false, if round(c, -1) = 3675.1 is true or false and so on. If you want to explore the fp world, try this: http://pages.cs.wisc.edu/~rkennedy/exact-float

    Fourth possibility: the rounding of 3675.05 changes if you are using Single or Double. With Single it’s 3675.1, with Double it’s 3675 🙂 Ah… the magical world of floats 🙂

    When you want to make mathematical tricks, please use the Currency type (it is a fixed point number and doesn’t have these problems).

    There is a last possibility, but it’s quite improbable: the Intel CPU stores intermediate results of Double operations as 80 bits fp and then “round” them to 64 bits on output. Some compilers/languages introduce an optional optimization (that is activated on the run of the program if possible) to use the SSE2 opcodes present in some processors instead of the FPU of the processor. The SSE2 operate on 64 bits fp, so no upcasting to 80 bits and downcasting from 80 bits. This could cause what you are seeing. Read here Differences between x87 FPU and SSE2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange but simple problem with the .animate() function in IE9. I
I am having a very strange problem in a simple program and have been
I have a strange build problem. I have a simple test program that sends
I have a strange problem. I have created a simple function to convert from
Please could a C# expert help with a simple problem which for some strange
I have this strange, yet maybe very simple problem.. I have a timer1 in
I've got a quite strange problem here. I'm calling some simple code via Ajax.Updater:
I have a simple problem in Python that is very very strange. def estExt(matriz,erro):
I am having a strange problem with a simple test app I am writing
I have very strange problem with mySQL and simple query with simple index. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.