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: 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 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon20-Mar-24 19:00
professionalJeremy Falcon20-Mar-24 19:00 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
bjongejan22-Mar-24 3:11
bjongejan22-Mar-24 3:11 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
Daniel Pfeffer20-Mar-24 18:53
professionalDaniel Pfeffer20-Mar-24 18:53 
This is why COBOL has a decimal type.

Your approach of using integers to represent currency will work, subject to a few caveats:
  1. Accounting rules require that calculations (e.g. multiplication, division) be performed with greater than 1 cent accuracy (5 decimal places, IIRC). This allows interest calculations, currency conversions etc. to work properly.
  2. Rounding is performed using accounting rules - round to nearest or AWAY. The difference between this and round to nearest or EVEN is when the fraction is exactly 0.5. If this case, one rounds AWAY from 0. For example, 3.145 would round to nearest or EVEN as 3.14, but round to nearest or AWAY as 3.15.
There may be other rules for accounting, but these are the major ones.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.

GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon20-Mar-24 18:56
professionalJeremy Falcon20-Mar-24 18:56 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jörgen Andersson20-Mar-24 21:40
professionalJörgen Andersson20-Mar-24 21:40 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon21-Mar-24 5:00
professionalJeremy Falcon21-Mar-24 5:00 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jörgen Andersson22-Mar-24 1:48
professionalJörgen Andersson22-Mar-24 1:48 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
jmaida21-Mar-24 11:15
jmaida21-Mar-24 11:15 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
jschell21-Mar-24 16:30
jschell21-Mar-24 16:30 
AnswerRe: What's y'all's favorite way of dealing with floating point precision? Pin
Sander Rossel20-Mar-24 22:35
professionalSander Rossel20-Mar-24 22:35 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon21-Mar-24 5:06
professionalJeremy Falcon21-Mar-24 5:06 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Sander Rossel21-Mar-24 5:54
professionalSander Rossel21-Mar-24 5:54 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon21-Mar-24 6:22
professionalJeremy Falcon21-Mar-24 6:22 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Sander Rossel23-Mar-24 1:43
professionalSander Rossel23-Mar-24 1:43 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 4:57
professionalJeremy Falcon23-Mar-24 4:57 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon23-Mar-24 5:00
professionalJeremy Falcon23-Mar-24 5:00 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon21-Mar-24 5:24
professionalJeremy Falcon21-Mar-24 5:24 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
englebart23-Mar-24 5:47
professionalenglebart23-Mar-24 5:47 
JokeRe: What's y'all's favorite way of dealing with floating point precision? Pin
Richard Deeming20-Mar-24 23:06
mveRichard Deeming20-Mar-24 23:06 
GeneralRe: What's y'all's favorite way of dealing with floating point precision? Pin
Jeremy Falcon21-Mar-24 5:00
professionalJeremy Falcon21-Mar-24 5:00 

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.