• Unappreciative Bastard (unregistered)

    Classic WTF: Waiting all day just to repost an old article.

  • dohpaz42 (cs) in reply to Unappreciative Bastard
    Unappreciative Bastard:
    Classic WTF: Waiting all day just to repost an old article.

    QFT

  • hoodaticus (cs)
    public string GetComment(CommentVersion version)
    {
       switch(version)
       {
          case CommentVersion.1:
             return "First";
          case CommentVersion.2:
             return "Tenth";
          case CommentVersion.2:
             return "Hundredth";
          default:
             return "FileNotFound";
       }
    }
    

    Addendum (2011-08-04 15:16): Damnit.

  • boog (cs)

    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.

  • hoodaticus (cs) in reply to boog
    boog:
    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.
    Enqueue lack of understanding that the int method Pete used is basically how the decimal type works anyway.
  • Pat Sajak (unregistered)

    TRWTF is people who don't own a copy of my ebook.

  • hoodaticus (cs) in reply to dohpaz42
    dohpaz42:
    Unappreciative Bastard:
    Classic WTF: Waiting all day just to repost an old article.
    QFT
    It beats trolling old threads where zunesis waits to rape us all.
  • GalacticCowboy (cs) in reply to hoodaticus
    hoodaticus:
    boog:
    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.
    Enqueue lack of understanding that the int method Pete used is basically how the decimal type works anyway.

    I sure hope that a decimal column is able to hold more than $214,000.00 or else its usefulness will be pretty limited.

  • moz (unregistered) in reply to boog
    Comment held for moderation.
  • hoodaticus (cs) in reply to GalacticCowboy
    GalacticCowboy:
    hoodaticus:
    boog:
    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.
    Enqueue lack of understanding that the int method Pete used is basically how the decimal type works anyway.

    I sure hope that a decimal column is able to hold more than $214,000.00 or else its usefulness will be pretty limited.

    It may or may not, depending on the type parameters.

  • Matt Westwood (cs) in reply to GalacticCowboy
    GalacticCowboy:
    hoodaticus:
    boog:
    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.
    Enqueue lack of understanding that the int method Pete used is basically how the decimal type works anyway.

    I sure hope that a decimal column is able to hold more than $214,000.00 or else its usefulness will be pretty limited.

    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.

  • TheCPUWizard (cs) in reply to Matt Westwood
    Adapt, but don't Change.

    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).

  • hoodaticus (cs) in reply to TheCPUWizard
    TheCPUWizard:
    Adapt, but don't Change.

    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).

    This. The decision to re-write, refactor, or adapt should be up to the developer. My policy is to fire any developers I can't trust with this responsibility, since they're useless to me.

  • operagost (cs)

    Didn't we see this scam in Superman III?

  • !sdrawkcab daer nac uoy (unregistered)

    Where's the WTF? This makes a lot of cents! ROFLMAO

    CAPTCHA: mara

  • frits (unregistered)

    My car is older than this wtf.

  • Gunslinger (unregistered)

    So, TRWTF is management. Or money.

  • Coyne (cs)

    I wonder: How much insanity must we eliminate before the result is sane? 10%? 50%?

  • Varchar (unregistered)

    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.

  • RichP (cs)

    FIRST!

    TENTH!

    ONE-HUNDREDTH!

  • Childish (unregistered) in reply to hoodaticus
    hoodaticus:
    boog:
    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.
    Enqueue lack of understanding that the int method Pete used is basically how the decimal type works anyway.

    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.

  • ideo (unregistered)

    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?

  • hoodaticus (cs) in reply to Childish
    Childish:
    hoodaticus:
    boog:
    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.
    Enqueue lack of understanding that the int method Pete used is basically how the decimal type works anyway.

    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.

    I almost fell for that one. Good job, troll.
  • Some damn Yank (unregistered) in reply to Childish
    Childish:
    hoodaticus:
    boog:
    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.
    Enqueue lack of understanding that the int method Pete used is basically how the decimal type works anyway.

    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.

    That's why REAL programmers work in base-1; any number can be factored with no fractions in base-1!
  • Son Of Thor (unregistered)

    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.

  • Cheong (unregistered)

    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...

  • MrB (unregistered) in reply to Son Of Thor
    Comment held for moderation.
  • Swedish tard (unregistered)

    Why not just call the rewrite a port? If management are messing with your turf (technical decisions) just mess with their turf (subterfuge)...

  • toshir0 (cs) in reply to hoodaticus
    hoodaticus:
    dohpaz42:
    Unappreciative Bastard:
    Classic WTF: Waiting all day just to repost an old article.
    QFT
    It beats trolling old threads where zunesis waits to rape us all.
    Zunesis is 10 years old and couldn't rape a disabled cat. Stop reading his comments. Or do so, but don't mention it.
  • Not Snoofle (unregistered)

    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?

  • secundum (unregistered) in reply to Son Of Thor
    Son Of Thor:
    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.
    Sure, but continually changing the scale is.

    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....

  • Sid Burn (unregistered)

    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.

  • Dave (unregistered) in reply to boog
    boog:
    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.

    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.

  • MeesterTurner (cs)

    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!!!!

  • Someone who can't be bothered to login from work (unregistered) in reply to Matt Westwood
    Matt Westwood:
    GalacticCowboy:
    hoodaticus:
    boog:
    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.
    Enqueue lack of understanding that the int method Pete used is basically how the decimal type works anyway.

    I sure hope that a decimal column is able to hold more than $214,000.00 or else its usefulness will be pretty limited.

    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.

    I believe Tom Kyte has a noose for people like you.

  • Peter (unregistered) in reply to ideo
    ideo:
    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?
    I think that it makes pretty clear that existing values were not converted:
    Article:
    It was then that Andy found several tables whose data had wildly different values in their price_in_cents columns, which now should've been named "prices_in_hundredths_of_cents," anyway. Furthermore, the values were meaningless. A value of 500,000 could mean $5,000.00, $500.00, or $50.00, depending on which version of the class library was in use at the time.
  • Helix (cs)

    I would like to be in Andy's place:

    myAccount.Balance <<= 4; // Multiply my cash by 16
    
  • Yojin (unregistered) in reply to Childish

    Son of a... Ok everyone fess up that got sniped by this bastard.

  • [use of trademarked name redacted] (unregistered) in reply to toshir0
    toshir0:
    hoodaticus:
    dohpaz42:
    Unappreciative Bastard:
    Classic WTF: Waiting all day just to repost an old article.
    QFT
    It beats trolling old threads where zunesis waits to rape us all.
    Zunesis is 10 years old and couldn't... I AM A HUGE FAGGOT PLEASE RAPE MY FACE!!!
    Hu-yuck! Let's sea them plearly wihtes, their, pretty!

    Now getton yur nees... Naw! Don't aveart yer eyes!

  • Schol-R-LEA (unregistered) in reply to Gunslinger
    Gunslinger:
    So, TRWTF is management. Or money.
    You're absolutely right. You should give me all of your money so I can dispose of it properly.
  • PedanticCurmudgeon (cs) in reply to Not Snoofle
    Not Snoofle:
    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?
    I see what you did there.

    Apparently, akismet thinks links to old comments are spam.

  • hoodaticus (cs) in reply to Cheong
    Cheong:
    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...

    NO EXCUSES! The non-WTF way to roll your own decimal data type is completely obvious!!

    Pete needs a brain implant, stat!

  • Im_rich (unregistered) in reply to Helix

    Doing that would give me $16 in my bank account (until my ex found out and would want her 17%)

  • hoodaticus (cs) in reply to Sid Burn
    Sid Burn:
    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.
    For the noobs - this guy is trolling or doesn't know wtf he's talking about, or both.
  • ContraCorners (cs) in reply to Im_rich
    Im_rich:
    Doing that would give me $16 in my bank account (until my ex found out and would want her 17%)
    Lucky you. If my ex ever found $16 in my bank account she'd insist that $17 of it was hers.
  • hoodaticus (cs) in reply to Swedish tard
    Swedish tard:
    Why not just call the rewrite a port? If management are messing with your turf (technical decisions) just mess with their turf (subterfuge)...
    Sun Tzu said "[t]here are some orders from the sovereign which must be disobeyed."
  • boog (unregistered) in reply to hoodaticus
    hoodaticus:
    Swedish tard:
    Why not just call the rewrite a port? If management are messing with your turf (technical decisions) just mess with their turf (subterfuge)...
    Sun Tzu said "[t]here are some orders from the sovereign which must be disobeyed."
    Who cares what some Chinese guy said thousands of years ago?
  • Ghost of Nagesh (unregistered)

    Andy and Pete obviously worked for Citibank!

  • Sick Burn (unregistered) in reply to hoodaticus
    hoodaticus:
    Sid Burn:
    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.
    For the noobs - this guy is trolling or doesn't know wtf he's talking about, or both.
    Was it something he said? Or just that he's posting on this board?
  • North Shore Beach Bum (unregistered) in reply to MeesterTurner
    MeesterTurner:
    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.

    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.

Leave a comment on “Classic WTF: Price In Nonsense”

Log In or post as a guest

Replying to comment #:

« Return to Article