Click here to Skip to main content
15,887,135 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
Marc Clifton21-Mar-24 2:28
mvaMarc Clifton21-Mar-24 2:28 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon21-Mar-24 4:58
professionalJeremy Falcon21-Mar-24 4:58 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Marc Clifton21-Mar-24 7:10
mvaMarc Clifton21-Mar-24 7:10 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
den2k8821-Mar-24 23:01
professionalden2k8821-Mar-24 23:01 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
Lloyd Folden 202422-Mar-24 5:33
Lloyd Folden 202422-Mar-24 5:33 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:06
professionalJeremy Falcon23-Mar-24 5:06 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
Matt Bond22-Mar-24 4:45
Matt Bond22-Mar-24 4:45 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:06
professionalJeremy Falcon23-Mar-24 5:06 
Matt Bond wrote:
When seeking consistency, I would wrap all of that in a utility class. This way I know it's consistent and works the same everywhere. If I need something a little different, then I either overload or add a default parameter as the occasion requires.
Ultimately, that's what I did. Except they were utility functions because I'm more functional than oop. Same concept though.
Matt Bond wrote:
I agree that storing the numerator and denominator would be the best way to prevent most headaches. In C#, I would use a Fraction struct for this (home grown if one doesn't exist already). Only collapse the fraction to a primitive type as necessary. This also has the benefit of letting you use money with a decimal value, so you don't have to do the extra math to get the cents back.
Yeah, it's an awesome idea. A pretty cool piece of code was posted earlier for rational numbers. My only concern with a language like JavaScript is the speed of that. In something like C/C++ I wouldn't think twice about using it.
Matt Bond wrote:
Speaking of money, you only have to store 4 decimals with money to be accurate for accounting purposes.
Whoops. I was storing 2. Thanks for this. Laugh | :laugh:
Matt Bond wrote:
However, we don't do multiplication and division on the money.
How do you do arithmetic on it then? Like, to calculate interest then?

Thanks for the reply btw.
Jeremy Falcon

GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Matt Bond25-Mar-24 2:52
Matt Bond25-Mar-24 2:52 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon26-Mar-24 10:38
professionalJeremy Falcon26-Mar-24 10:38 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
Bruce Patin22-Mar-24 6:01
Bruce Patin22-Mar-24 6:01 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:07
professionalJeremy Falcon23-Mar-24 5:07 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
charlieg22-Mar-24 8:46
charlieg22-Mar-24 8:46 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:09
professionalJeremy Falcon23-Mar-24 5:09 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
#realJSOP22-Mar-24 10:16
mve#realJSOP22-Mar-24 10:16 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:11
professionalJeremy Falcon23-Mar-24 5:11 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
#realJSOP24-Mar-24 11:54
mve#realJSOP24-Mar-24 11:54 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon26-Mar-24 10:42
professionalJeremy Falcon26-Mar-24 10:42 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
rjmoses23-Mar-24 0:00
professionalrjmoses23-Mar-24 0:00 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:15
professionalJeremy Falcon23-Mar-24 5:15 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
charlieg31-Mar-24 4:31
charlieg31-Mar-24 4:31 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
Stacy Dudovitz23-Mar-24 13:41
professionalStacy Dudovitz23-Mar-24 13:41 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon24-Mar-24 4:47
professionalJeremy Falcon24-Mar-24 4:47 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Stacy Dudovitz24-Mar-24 15:59
professionalStacy Dudovitz24-Mar-24 15:59 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon26-Mar-24 10:41
professionalJeremy Falcon26-Mar-24 10:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.