Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Perl
Perl Misc
Compare, two identical numbers are not the same?!
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Jürgen Exner, post: 4866998"] That would be one common approach to avoid any inaccuracies caused by floating point arithmetic. Think of it as doing all calculations in cent instead of in dollar or euro and only convert them into a 'human-friendly" format when printing or reading those amounts. If this works for your application then it's the best posible solution. However, computer numerics are tricky, there is a reason why it is a subject matter at university, and even that method is not fool-proof. Example: when calculating interest on a long list of accounts, even if you manage them internally in cent, you may get a different result when adding up all the interest paid to each account compared to calculating the sum of all accounts and then the interest on the lump sum. Those rounding errors are what's driving accountants and bankers nuts because it takes forever to find out where and why those 3 cents went missing in action while the missing million will be spotted immediately. It is ok to compare floats for smaller/larger. But instead of checking for equal you must check if the difference between the two numbers is smaller than some tiny number. How large that tiny number is depends on your application area, but it will never be 100% accurate. jue [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
Compare, two identical numbers are not the same?!
Top