Click here to Skip to main content
15,888,521 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: To get a %age divide the number by the number of decimal places defined on the column Pin
CHill6013-Dec-19 1:42
mveCHill6013-Dec-19 1:42 
GeneralRe: To get a %age divide the number by the number of decimal places defined on the column Pin
Marc Clifton13-Dec-19 2:39
mvaMarc Clifton13-Dec-19 2:39 
GeneralRe: To get a %age divide the number by the number of decimal places defined on the column Pin
Nelek13-Dec-19 3:04
protectorNelek13-Dec-19 3:04 
GeneralRe: To get a %age divide the number by the number of decimal places defined on the column Pin
Marc Clifton13-Dec-19 4:05
mvaMarc Clifton13-Dec-19 4:05 
GeneralRe: To get a %age divide the number by the number of decimal places defined on the column Pin
Nelek13-Dec-19 4:11
protectorNelek13-Dec-19 4:11 
GeneralRe: To get a %age divide the number by the number of decimal places defined on the column Pin
CHill6013-Dec-19 5:07
mveCHill6013-Dec-19 5:07 
GeneralRe: To get a %age divide the number by the number of decimal places defined on the column Pin
Nelek13-Dec-19 3:08
protectorNelek13-Dec-19 3:08 
GeneralRe: To get a %age divide the number by the number of decimal places defined on the column Pin
Tiger1250619-Dec-19 15:33
Tiger1250619-Dec-19 15:33 
This is a really old programming problem. How would you store a running total of a bank account? Since it has dollars and cents, how about a float?

Ok, so then you run into the "floating-point rounding error" problem.

>>> 0.1+0.1+0.1
0.30000000000000004


Well... that's pretty bad to be adding/dropping pennies every trillion transactions or so because of cumulative binary representation of decimal digit errors. What else can we do?

One of the commonly chosen ways is to used fixed decimal. i.e. Assume a fixed number of decimals and represent everything as integers. One no longer has to worry about fractions of a penny creeping up on you over time if you work in discrete units of pennies. i.e. 100-97 = 3, never 0.30000000000000004

Well... then your manager comes in and says, we need to be able to track hundredths of a penny because the state tax paid even including fractions of a penny. So it is deemed that 4-digits is enough precision to satisfy the need. Now 10000 - 9700 = 300 is still okay, is never gonna be 300.00000000000004 and the same situation applies as before.

But your front-end buddies didn't update the website to account for the fact that the database now assumes 4 digits of precision. And thus the problem is born.

Fun trivia: "Office Space" movie characters took advantage of this to siphon off millions of dollars back when this was a thing in the 80s-90s-00s.
GeneralRe: To get a %age divide the number by the number of decimal places defined on the column Pin
CHill6019-Dec-19 21:08
mveCHill6019-Dec-19 21:08 
GeneralDev time waster ala JSON dialect PinPopular
raddevus9-Dec-19 10:24
mvaraddevus9-Dec-19 10:24 
GeneralRe: Dev time waster ala JSON dialect Pin
Jon McKee9-Dec-19 13:13
professionalJon McKee9-Dec-19 13:13 
GeneralRe: Dev time waster ala JSON dialect Pin
raddevus10-Dec-19 3:32
mvaraddevus10-Dec-19 3:32 
GeneralRe: Dev time waster ala JSON dialect Pin
kmoorevs10-Dec-19 6:36
kmoorevs10-Dec-19 6:36 
GeneralRe: Dev time waster ala JSON dialect Pin
raddevus11-Dec-19 2:40
mvaraddevus11-Dec-19 2:40 
GeneralRe: Dev time waster ala JSON dialect Pin
Sander Rossel11-Dec-19 2:10
professionalSander Rossel11-Dec-19 2:10 
GeneralRe: Dev time waster ala JSON dialect Pin
raddevus11-Dec-19 2:46
mvaraddevus11-Dec-19 2:46 
GeneralRe: Dev time waster ala JSON dialect Pin
Sander Rossel11-Dec-19 3:42
professionalSander Rossel11-Dec-19 3:42 
GeneralRe: Dev time waster ala JSON dialect Pin
raddevus11-Dec-19 4:32
mvaraddevus11-Dec-19 4:32 
GeneralRe: Dev time waster ala JSON dialect Pin
Sander Rossel11-Dec-19 4:37
professionalSander Rossel11-Dec-19 4:37 
GeneralRe: Dev time waster ala JSON dialect Pin
F-ES Sitecore11-Dec-19 3:47
professionalF-ES Sitecore11-Dec-19 3:47 
GeneralRe: Dev time waster ala JSON dialect Pin
  Forogar  11-Dec-19 4:27
professional  Forogar  11-Dec-19 4:27 
GeneralRe: Dev time waster ala JSON dialect Pin
Sander Rossel11-Dec-19 4:39
professionalSander Rossel11-Dec-19 4:39 
GeneralRe: Dev time waster ala JSON dialect Pin
raddevus11-Dec-19 4:34
mvaraddevus11-Dec-19 4:34 
GeneralRe: Dev time waster ala JSON dialect Pin
Bernhard Hiller5-Jan-20 21:49
Bernhard Hiller5-Jan-20 21:49 
GeneralRe: Dev time waster ala JSON dialect Pin
englebart11-Dec-19 2:50
professionalenglebart11-Dec-19 2:50 

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.