Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Capture division by zero
Re: Capture division by zero [message #58697 is a reply to message #58696] |
Mon, 25 July 2022 09:39   |
 |
mirek
Messages: 14256 Registered: November 2005
|
Ultimate Member |
|
|
jjacksonRIAB wrote on Mon, 25 July 2022 03:37
Anyone have an opinion on this one? I'm of the opinion that floats should not be used to represent any kind of currency or bank balance and I tended to replace them in C# with Decimal when I worked for an accounting department. I haven't checked but does U++ have a fixed-point decimal type for dealing with currency and other numbers where float accuracy is not good enough? If not maybe one should be made.
Interesting question. For what is worth, I was doing applications dealing with money for years and while I know the theory, I have simple used double the whole time, to no ill effects.
I guess that in the end, you are usually rounding to 2 decimals after the point. You would need to sum millions of values to get a difference in printed output, so for the most time, it is just fine.
That said, Decimal datatype would be fine.
BTW, I do not think float or not float is the issue here, but underlying representation. Now I was not looking into this for some time, but I think that to be "financial correct" you need decimal representation instead of binary (some form of BCD) so that you can represent decimal fractional numbers exactly.
Mirek
[Updated on: Mon, 25 July 2022 09:39] Report message to a moderator
|
|
|
 |
|
Capture division by zero
By: koldo on Fri, 16 October 2020 09:15
|
 |
|
Re: Capture division by zero
By: Didier on Sat, 17 October 2020 23:53
|
 |
|
Re: Capture division by zero
By: koldo on Sun, 18 October 2020 21:38
|
 |
|
Re: Capture division by zero
By: koldo on Mon, 19 October 2020 07:57
|
 |
|
Re: Capture division by zero
By: Didier on Mon, 19 October 2020 20:54
|
 |
|
Re: Capture division by zero
By: koldo on Tue, 20 October 2020 08:02
|
 |
|
Re: Capture division by zero
By: Didier on Tue, 20 October 2020 20:58
|
 |
|
Re: Capture division by zero
By: koldo on Wed, 21 October 2020 07:55
|
 |
|
Re: Capture division by zero
By: Didier on Wed, 21 October 2020 20:29
|
 |
|
Re: Capture division by zero
By: mirek on Tue, 27 October 2020 09:27
|
 |
|
Re: Capture division by zero
By: koldo on Tue, 27 October 2020 10:58
|
 |
|
Re: Capture division by zero
|
 |
|
Re: Capture division by zero
By: mirek on Mon, 25 July 2022 09:39
|
 |
|
Re: Capture division by zero
|
 |
|
Re: Capture division by zero
By: Klugier on Sun, 18 October 2020 21:21
|
 |
|
Re: Capture division by zero
By: Klugier on Mon, 26 October 2020 23:51
|
 |
|
Re: Capture division by zero
By: mirek on Tue, 27 October 2020 11:53
|
 |
|
Re: Capture division by zero
By: koldo on Tue, 27 October 2020 17:08
|
 |
|
Re: Capture division by zero
By: Didier on Tue, 27 October 2020 18:58
|
 |
|
Re: Capture division by zero
By: koldo on Tue, 27 October 2020 19:21
|
Goto Forum:
Current Time: Wed Apr 30 11:49:38 CEST 2025
Total time taken to generate the page: 0.03891 seconds
|