Click here to Skip to main content
15,886,919 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.

 
GeneralRe: Latest Alien movie - teaser trailer Pin
glennPattonWork320-Mar-24 23:15
professionalglennPattonWork320-Mar-24 23:15 
GeneralRe: Latest Alien movie - teaser trailer Pin
Richard Deeming20-Mar-24 23:34
mveRichard Deeming20-Mar-24 23:34 
GeneralRe: Latest Alien movie - teaser trailer Pin
yacCarsten20-Mar-24 23:45
yacCarsten20-Mar-24 23:45 
GeneralRe: Latest Alien movie - teaser trailer Pin
glennPattonWork321-Mar-24 0:30
professionalglennPattonWork321-Mar-24 0:30 
JokeRe: Latest Alien movie - teaser trailer Pin
PIEBALDconsult21-Mar-24 2:10
mvePIEBALDconsult21-Mar-24 2:10 
GeneralRe: Latest Alien movie - teaser trailer Pin
glennPattonWork321-Mar-24 4:12
professionalglennPattonWork321-Mar-24 4:12 
GeneralLast one for a while: I didn't think that orthopedic shoes would help PinPopular
jmaida20-Mar-24 16:43
jmaida20-Mar-24 16:43 
QuestionWhat's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon20-Mar-24 16:11
professionalJeremy Falcon20-Mar-24 16:11 
Not sure if this counts as a programming question, since I'm not asking for code but rather preference. I'm in a project that requires complete accuracy on numbers. So, given the following...

We all know the famous of examples of stuff like this:
JavaScript
0.1 + 0.2 // 0.30000000000000004
Up until now, I've been content with rounding off any operations after the fact and calling it a day, as close enough was good enough. For applications, say that deal with currency, the age old trick is to just use integers based on a cent value. So, a $1.23 would be stored as 123 in a variable. Sweet, but, consider this:
JavaScript
// $123.45 / $2.25
12345 / 225 // 54.86666666666667
If I move along powers of the base, I never run into issues. But for your typical run of the mill calculations, even with integers, you still have to deal with fractional floating points in the arithmetic.

So, I've been using integers and rounding off any calculations to their nearest integer value. Maybe sometimes I'll floor or ceil depending on context, but that's been my current solution, which is a lot more accurate but not 100% accurate. But, good enough-ish.

Soooo....

1) You guys prefer using a library to handle stuff like this? IMO I don't use one for arithmetic because most libraries for this (at least in JavaScript) are clunky and slow and don't really do a better job anyway.

2) You think integers and rounding is also the way to go? Keeps crap simple and all that, despite needing to remember to always round after division calculations or calculations against fractional types.

3) Never do arithmetic? Tell the user to go home.
Jeremy Falcon


modified 20-Mar-24 22:18pm.

AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
jmaida20-Mar-24 16:39
jmaida20-Mar-24 16:39 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon20-Mar-24 16:53
professionalJeremy Falcon20-Mar-24 16:53 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
jmaida20-Mar-24 17:29
jmaida20-Mar-24 17:29 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? PinPopular
Mircea Neacsu20-Mar-24 16:53
Mircea Neacsu20-Mar-24 16:53 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon20-Mar-24 16:55
professionalJeremy Falcon20-Mar-24 16:55 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Mircea Neacsu20-Mar-24 16:59
Mircea Neacsu20-Mar-24 16:59 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon20-Mar-24 17:03
professionalJeremy Falcon20-Mar-24 17:03 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Mircea Neacsu20-Mar-24 17:05
Mircea Neacsu20-Mar-24 17:05 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon20-Mar-24 17:08
professionalJeremy Falcon20-Mar-24 17:08 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Mircea Neacsu20-Mar-24 17:30
Mircea Neacsu20-Mar-24 17:30 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon20-Mar-24 18:54
professionalJeremy Falcon20-Mar-24 18:54 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Andre_Prellwitz24-Mar-24 20:35
Andre_Prellwitz24-Mar-24 20:35 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon26-Mar-24 10:39
professionalJeremy Falcon26-Mar-24 10:39 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
jmaida20-Mar-24 17:33
jmaida20-Mar-24 17:33 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
Amarnath S20-Mar-24 18:13
professionalAmarnath S20-Mar-24 18:13 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Daniel Pfeffer20-Mar-24 18:55
professionalDaniel Pfeffer20-Mar-24 18:55 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
jmaida21-Mar-24 14:51
jmaida21-Mar-24 14:51 

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.