- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Classic WTF: Waiting all day just to repost an old article.
Admin
QFT
Admin
Addendum (2011-08-04 15:16): Damnit.
Admin
Cue a bunch of angry complaints about Andy's DECIMAL solution, not to mention a solid day's worth of comments bitching and arguing about how to store money in databases.
Admin
Admin
TRWTF is people who don't own a copy of my ebook.
Admin
Admin
I sure hope that a decimal column is able to hold more than $214,000.00 or else its usefulness will be pretty limited.
Admin
Admin
Admin
Hmm ... probably be better off storing it as a string of arbitrary length, and then using one or two of the many routines as documented on this forum to convert from this to whatever numerical value is appropriate at the time.
Admin
Andy was WRONG....He should have changed jobs, and not "adapted" to submitting to an unreasonable request (presuming the statements about the actual condition of the overall codebase are true).
Admin
Admin
Didn't we see this scam in Superman III?
Admin
Where's the WTF? This makes a lot of cents! ROFLMAO
CAPTCHA: mara
Admin
My car is older than this wtf.
Admin
So, TRWTF is management. Or money.
Admin
I wonder: How much insanity must we eliminate before the result is sane? 10%? 50%?
Admin
If you store it as a varchar(50), not only can you store the prices just as it is- $87,l38.83 means just that- but if you ever need to store higher numbers, the change is pretty easy.
Admin
FIRST!
TENTH!
ONE-HUNDREDTH!
Admin
No, the DECIMAL type should use base-10 "decimal" numbers. There are serious rounding errors with base-2. The classic is 10 cents = 1/10 becomes a repeating fraction in base-2.
Admin
Those dicky wannabe programmers, such as Pete, I could murder w/o a remorse. I get so fucking angry because of things like this.
BTW, the author didn't exactly mention that existing values were converted as the version of Money changed, right? So, past $1.00 (100 c) suddenly became, first, $0.10, then $0.01 - am I right?
Admin
Admin
Admin
realy storing money as an int is not a WTF but almost standard practics in the banking world. and storing 1/10 of a cent is not unusual.
Admin
Think about all the nasty bugs we faced when we cannot balance financial data with float data type in the 16-bit days...
I'll give Pete the benefit of doubt that his code was also ported from some yet older source...
Admin
Indeed. It is in use even today in the US:
http://en.wikipedia.org/wiki/Mill_(currency)
Admin
Why not just call the rewrite a port? If management are messing with your turf (technical decisions) just mess with their turf (subterfuge)...
Admin
Admin
But what if management later decides that price-in-cents, subsequently price-in-tenths-of-cents, subsequently price-in-hundreths-of-cents should now be price-in-roman-numerals?
Admin
I think the issue is more the sliding goal posts as they go from storing at 1cent granularity to 1/10th cent etc....
Of course, provided that particular field was always updated when they changed the granularity, there might be less issue....
Admin
Storing Money as an INT is the only correct way. DECIMAL does not work like shifting an INT how somebody tells before. It primary works with a lot of rounding. That's the reason why you should never use a decimal for money.
That the values itself changed and a value before that was $0.10 is now $1 is also wrong.
Pete could have upgraded the database before and all the values. It is one simple "ALTER TABLE" statement to upgrade the values to a new base. But only from seeing the code, no one could say that Pete doesn't run this.
The real WTF is, if you think that Pete has done anything wrong.
Admin
I've seen worse done with financial amounts. For example ASN.1 stores financial values as ASN.1 INTEGERs, which go up to 3,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000. Some standards authors decided that this wasn't enough and broke it down into two values, a base and an exponent, because apparently the range of an INTEGER, although sufficient to enumerate the number of subatomic particles in the universe, wasn't sufficient for moderate-sized financial transactions.
Admin
A long-standing part of our core app stores how long someone has been living at an address.
The sensible solution would be to store it in an integer for months, so if you wanted 1 year 6 months, you store 18. Nice and easy to work with.
But no. Before I began working on it, someone had the bright idea of using decimals, so 18 months is then stored as 1.6... which is ok for the first 9 months, and then you get to, sa, 1yr 10mths which is 1.10 - which is the same is 1yr 1mth...
Cue constant frustration, and due to the amount of work to do a best-guess-conversion and store it in months and use that field across all of the related apps, management lives with it to this day... 10 years later!!!!
Admin
I believe Tom Kyte has a noose for people like you.
Admin
Admin
I would like to be in Andy's place:
Admin
Son of a... Ok everyone fess up that got sniped by this bastard.
Admin
Now getton yur nees... Naw! Don't aveart yer eyes!
Admin
Admin
Apparently, akismet thinks links to old comments are spam.
Admin
Pete needs a brain implant, stat!
Admin
Doing that would give me $16 in my bank account (until my ex found out and would want her 17%)
Admin
Admin
Admin
Admin
Admin
Andy and Pete obviously worked for Citibank!
Admin
Admin
Actually, the sensible solution would be store a date for when they moved to that address and a date for when they moved from that address (this could be null if that address is still valid). Or you could fudge it with a number like 201108 to mean August of 2011. Now you wouldn't need to update all records every month just to keep your database accurate.