• Prometheus (unregistered)

    What the hell? The most WTF's in this are due to the anonymization?

    The Doors - The End

  • csrster (unregistered) in reply to ChiefCrazyTalk
    Anonymous:
    The real WTF (tm) is that this is some of the best commented, clearest code that I have ever seen. Too bad it's just silly. That said, representing money as integers is not unusual.


    "best commented"? Are you nuts? The method itself has no documentation at
    all. What do its parameters mean? What values are legal for them? What is the
    method's behaviour if its parameters assume illegal values? What does it
    return in the unlikely event of it being used correctly?

    (And a bonus question - what does the method for calculating interest look like ? :-))
  • (cs) in reply to WeatherGod
    WeatherGod:


    Wait a minute, that is a database call?  So, for each time I want to print out information, I must pay a penalty of an I/O call?  Then, with this database possibly being used by a lot of simultaneously running programs, I can see this system screaming to a crawl, given enough of a load, of course.



    Really?  You think??

  • csrster (unregistered) in reply to elmegil
    Anonymous:
    Ok, so the code sucks.

    And it doesn't take into account some obvious cases ($0.00 is mentioned above).

    But this sounds like you are presuming that money is always done in floating point, when in fact, using fixed point decimal (ok, so this doesn't really do that either), and representing the numbers as integers, is generally much simpler.  Depending on your integer math implementation (does it round?) you can avoid things like "$0.9999999999999999999" etc.

    There seem to be plenty of reasons to dismiss this code as WTF without attacking the idea of integer money.


    Funnily enough, there was a thread on slashdot yesterday on the very subject of types for representing money.
  • Michael (unregistered)

    Anyone even contemplating using floating point numbers for currency should be shot. Immediately.

  • Chris (unregistered)

    It's all well and good, but it should have a database table (TBL_NUMBER_BEAUTIFICATION or somesuch) that stores each number with its beautified version.

    You'd need a DBA to add in extra numbers when you needed them of course, but that's fine and what enterprise is all about.

    CAPTCHA: bedtime .. 9.30am - yeah I should be in bed still :)

  • TP (unregistered) in reply to Pyrolistical
    Anonymous:
    Wow.

    Here's a site to catch other people's wtfs and right in the text they promote a wtf in itself.

    You should never represent money with floating point!  You will be out of a job real fast once your accounting department can't figure out why doesn't everything total at the end of the day.

    Another value that should never be represented as a decimal is a unit of time.  Always use an integer for time, or else you will run into floating point issues just as you did if you used it to represent money.


    I'd say the WTF is that you don't seem to differentiate between float and decimal, two distinct data types in C# (the language of the example). float having its well-known (though often misunderstood) limitations, and decimal being a datatype specifically designed for working with financial calculations and other fractional calculations in base 10.

    Quite frankly, I think that many of the commenters on this site are prime candidates for WTF code creation if the quality of their comments are any basis by which to judge.
  • Sam (unregistered)


    <font color="#000000" face="Courier New">//throw exception if bad input</font>
    <font color="#d3d3d3" face="Courier New"><font color="#000000">
    if (field.Length == 0 || entity.Length == 0) return "-1";</font>
    </font>

    Erm, that's not an exception. That scares me.
  • Rock Paper Scissors (unregistered)

    I don't often get drawn into replying to these WTFs, but on this occasion I feel I have something to actually contribute.

    clears throat

    GRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARRRRRRRRRRRRRGGGGGHHHHHHHH! DIE DIE DIE DIE DIE DIE!

    pant pant

    My, that is awful. It's about the first thing I've seen on TDWTF which, if I encountered it in real life, would make me just silently leave the building.

    And the city.

    And move to Bolivia.

    Mm, ceviche.

  • bool-man (unregistered) in reply to Anonymous
    Anonymous:
    You know, computers use binary. Wouldn't it be much better to get rid of all datatypes except for booleans?
    Anyone remember:
    
    enum Bool {
         TRUE,
         FALSE,
         FILE_NOT_FOUND
    };
    

    ???

  • Asif Youcare (unregistered) in reply to Alex Papadimoulis

    Where's the database call? I cannot see one.


  • (cs) in reply to Ford351-4V
    Ford351-4V:
    Makes me wonder what the ReturnBooleanResult() method looks like.


    Luckily, a sane programmer remove the hideous mess that was on that method, and replaced it with a single line that does exactly the same thing as the previous version:

    return "MAYBE";


  • (cs) in reply to smbell
    smbell:

    Once again the comments approach the level of WTF as the code example.  Storing numbers and decimal when dealing with money is unacceptable due to the imprecise nature of decimal numbers.  They are merely an approximation, not an exact value.

    This obscures the fact that most modern languages (.NET included) have support for accurate decimal number representation in the form of some math library or class (I think in .NET it is BigDecimal?).  That is 'the real WTF'.


    Funny how you quote .NET, without knowing that the .NET decimal type is a 96-bit integer and an 8-bit (I think) decimal exponent. And presumably a sign bit. Amazing waste of space, given that they had at least 7 other bits to use (if not 23) without making it take more space.

    Financial calculations are NOT about 'accuracy'. They're about correctness. You can't make sure that your calculations are 'to the nearest whatever' (Does 0.499999... round up or down? you need to wait until you find a digit that's not a 9, which may never happen). You can make sure that they follow your local laws, assuming that it's possible (e.g. you can calculate UK VAT in three different ways, which mostly differ by where they round).

    Sadly, .NET doesn't provide things it should, like Decimal.HasMoreDecimalsThan(int places), Decimal.IsInteger() (which compiles to hasmoredecimalsthan(0)), and proper integer devision (floor(a/b) is not guaranteed to be the same as (a div b), e.g. if a is close to b and the calculation rounds up).
  • (cs) in reply to Terance
    Anonymous:
    There is another WTF here.
    They used a StringBuilder object.
    The StringBuilder is great for large data, or data that is going to be appended to a lot. But it is going to impace performance when you start to have more than a few dozen.

    This is in a class used for every integer/decimal data type. There is going to be quite a few here.

    Their attempt increase speed is going to have the opposite effect.  


    The StringBuilder is created and destroyed within the same function. No WTF here. ANY time you use +, you create a StringBuilder (In Java 1.5, at least, a+b+c compiles to new StringBuilder(a).Append(b).Append(c).ToString(). The real WTF is that versions before 1.5 used StringBuffer, which is slower since it's thread-safe).

    And a few dozen objects is peanuts.
  • (cs) in reply to Alex Papadimoulis

    Alex Papadimoulis:
    I got totally confused trying to anonymize this; the original was much harder to follow. Passing in 120 with places=1 should return 12.0, Passing in 2 with places=3 should return 0.002; who knows if the revised one still does that.

    The code I'm currently seeing looks like it would prepend places + 1 zeroes to the "number" before putting in the decimal point somewhere in the middle, so passing in 120 with places == 1 would return 0012.0, passing in 2 with places == 3 would return 00.002 and it might have been enough to prepend places rather than (places + 1) zeroes.

  • Dark (unregistered) in reply to Simon
    Simon:
    Yes, I am the Simon that submitted this.  It looks like Alex got confused when anonymizing the part at the end that actually does the "math" (I did too, at first).  This is the actual algorithm:

    Start with the string "1".
    Append "0" to that string the appropriate number of times for the places from the metadata.
    Convert that resulting string to a number, divide the parameter by it, convert that floating-point number back to a string, then return that float-in-a-string.
    So... once again, what we're seeing isn't even close to the real code. There's a vague similarity of function in this case, but that's all. What we see is a function that does string manipulation. What you reported was a function that used floating-point math to mangle their precious beautiful integers, which would have been a real WTF. Or might have been, if we can believe any of the rest of the story.

    And this made-up code is again presented as if it were a real example of professional code.

  • matthew muscari (unregistered) in reply to exussum
    Anonymous:
    It's standard practice to represent floats/decimals in integer form. Otherwise you get funky rounding things happening when you multiply or divide. It's just a fact of life. It gets worse in finance, as some things go to 32'nds and beyond and you are using a large value to begin with.

    Soo... typically you'd do everything in integer/long form and display it in float/decimal form to minimize the damage by using String manipulation.

    No, finance people do not like it when numbers get botched out of their control. :)




    well if they want to avoid that they shouldn't be using pentium pros!! (floating point bug... haha...)

  • No, Your Name (unregistered) in reply to Dark

    Anonymous:
    Simon:
    Yes, I am the Simon that submitted this.  It looks like Alex got confused when anonymizing the part at the end that actually does the "math" (I did too, at first).  This is the actual algorithm:

    Start with the string "1".
    Append "0" to that string the appropriate number of times for the places from the metadata.
    Convert that resulting string to a number, divide the parameter by it, convert that floating-point number back to a string, then return that float-in-a-string.
    So... once again, what we're seeing isn't even close to the real code. There's a vague similarity of function in this case, but that's all. What we see is a function that does string manipulation. What you reported was a function that used floating-point math to mangle their precious beautiful integers, which would have been a real WTF. Or might have been, if we can believe any of the rest of the story.

    And this made-up code is again presented as if it were a real example of professional code.

    You're kidding, right?!? So if this were an architectural critique site, and the daily example was "skyscrapers with no elevators," you'd be the fucktard that'dcompalin, "I visited that building, and, although there are only stairs, the lobby colour is GREEN not BLUE!"

    The REAL problem lately is all the crap comments from people like you. Let's see some more moderation here, please.

  • (cs)

    Meeting:

    developer 1 : now lets do dates! I hate how all of society makes those hardcore "seconds" appear beautiful with their corrupt "minutes", "hours", and "days"....

    developer 2 : yeah!! woohooo!! seconds rock!

    developer 3 :  waidamin! are seconds really the base unit of time?  I mean... SI units all aside... isn't the second actually a particular multiplication of Planks time.. the shortest possible time in the universe...

    developer 1 : pah! corruption!

    developer 2 : yeah! woohoo!! Plank rocks!!

    etc

  • Dark (unregistered) in reply to No, Your Name
    Anonymous:
    You're kidding, right?!? So if this were an architectural critique site, and the daily example was "skyscrapers with no elevators," you'd be the fucktard that'dcompalin, "I visited that building, and, although there are only stairs, the lobby colour is GREEN not BLUE!"

    No, I'd be complaining that the story is accompanied by a picture of the Eiffel Tower.

  • (cs) in reply to Alex Papadimoulis
    Alex Papadimoulis:

    its me:
    Jon W:
    Enough with the anonymyzing already. If it's really that bad, just run it through a formatter (change brace style) and rename the variables by pre-pending "paula" to each.


    Yeah, seriously Alex, this anonymyzing is getting bad. Change the variables to "string1", "string2", "int1", "int2", tweak the namespaces/classnames slightly and be done with it....

    -me

    Sure, no problem. But you guys got my back when I get sued for exposing proprietary trade secrets, copyright violation, libel, defamation, DMCA, causing someone to lose his job, etc., right? Then again, who could possibly recognize their own work if some one went so far as to change a word or two? Riiiiggghhhttt .....

    Come one guys, if you're thinking "OMFGWTFBBQ!! He used a | instead of a ||" when you see the article, you need to go back and read it again. You missed the part where the CEF system uses only numbers and strings and requires a database call to convert integers to decimals.



    I don't think many of us had large issues with the logical/bitwise Or mishap. Also, simply because a system only uses integers and strings, it isn't necessarily a WTF. You may think so, but it is quite the contrary. Still, the code you originally posted was no where near the same code as what was submitted, and even the code now is different. Maybe what you need is a good disclaimer for people posting code, and maybe require them to alter it themselves. Apparently Alex, your refactoring skills are lacking to the point of being a WTF themselves. The current code in the post still misses the " Convert that resulting string to a number, divide the parameter by it, convert that floating-point number back to a string, then return that float-in-a-string.".
  • RichNFamous (unregistered) in reply to Rudi
    Anonymous:
    Anonymous:
    Well that's great, that's just fuckin' great man. Now what the fuck are we supposed to do? We're in some real pretty shit now man... That's it man, game over man, game over! What the fuck are we gonna do now? What are we gonna do?


    Nice quote from Aliens, weird nobody else commented before?


    Alien, not Aliens, puhleeze!
  • xero (unregistered)

    I refuse to believe this is real. Nope. Never happened.

  • (cs) in reply to Pyrolistical
    Anonymous:
    Wow.

    Here's a site to catch other people's wtfs and right in the text they promote a wtf in itself.

    You should never represent money with floating point!  You will be out of a job real fast once your accounting department can't figure out why doesn't everything total at the end of the day.

    Another value that should never be represented as a decimal is a unit of time.  Always use an integer for time, or else you will run into floating point issues just as you did if you used it to represent money.


    This forum drives me crazy. Decimal and integer are not opposites.

    What is 99? It is an integer. It is also a decimal number. (Well its not base-2 through base-9, that's for sure.) Decimal simply refers to the base. Deci is from the Latin for 10. BASE *10*! Not fractional -- BASE 10!

    P.S. Oracle uses fractions to represent time.
  • Chris (unregistered) in reply to Jud
    Jud:
    BRING BACK FOOSBALL GIRL!!!!!!!

    QFT

    Captcha: Anonymous

    But really, why do you have to remember the persons name when you want to quote them ^^

  • (cs) in reply to TP
    Anonymous:

    I'd say the WTF is that you don't seem to differentiate between float and decimal, two distinct data types in C# (the language of the example). float having its well-known (though often misunderstood) limitations, and decimal being a datatype specifically designed for working with financial calculations and other fractional calculations in base 10.

    Quite frankly, I think that many of the commenters on this site are prime candidates for WTF code creation if the quality of their comments are any basis by which to judge.


    Thank God. There is one other person here who an iota of sense. I have said this same exact thing 2 or 3 times in this thread.

    This reminds of the time when everybody went nuts over that "obfuscated version numbering" WTF and wrote in with suggestions to "dehash" the obfuscated string when support needs to map it to a working version number ... using the word "dehash" (and not kidding) is a bigger WTF than anything posted on the main page of this site in months.
  • (cs) in reply to GoatCheez
    GoatCheez:

    I don't think many of us had large issues with the logical/bitwise Or mishap. Also, simply because a system only uses integers and strings, it isn't necessarily a WTF. You may think so, but it is quite the contrary. Still, the code you originally posted was no where near the same code as what was submitted, and even the code now is different. Maybe what you need is a good disclaimer for people posting code, and maybe require them to alter it themselves. Apparently Alex, your refactoring skills are lacking to the point of being a WTF themselves. The current code in the post still misses the " Convert that resulting string to a number, divide the parameter by it, convert that floating-point number back to a string, then return that float-in-a-string.".


    Right on! Alex, whatever somebody sends you, POST IT VERBATIM! You can't get sued for posting something somebody sent you -- just blank out obvious references to a business, such as copyrights in the comments section. But if somebody is sending you proprietary code that they shouldn't be sending you, that is THEIR fault. I would never send in code because I value my job and it would be hugely illegal. The worst that could happen is somebody sees the code and asks you to take it down. I love this site, but transliterating a code fragment into an entirely different language and making several mistakes along the way makes everybody jump on the WTFs that you introduced, and we completely miss the real point.

    Second rule: nobody here should make fun of other people's code if they don't truly understand what is going on. There are a lot of opinions here about how to properly do money math -- only a couple people are correct. And yes, there is such a thing as "correct" -- it is mandated by law and industry standards. If you work for a large financial corporation, then money math is ALWAYS DONE IN DECIMAL.
  • That guy (unregistered) in reply to savar

    savar:
    You can't get sued for posting something somebody sent you

    Sweet!!! Free legal advise from savar!

    I'm assuming you're also an expert in taxes and accounting too, so could you help me with some deductions I'd like to do this year?

  • (cs) in reply to savar
    savar:


    Right on! Alex, whatever somebody sends you, POST IT VERBATIM! You can't get sued for posting something somebody sent you


    Well, he could - he lives in the U.S. of A. after all.  Whether the suit would be successful is a different question.  Alex is probably justified to be on the safe side by changing the code he receives into something completely different.  Whether the result is the kind of WTF that readers of this site eagerly anticipate every day is another question.

    There is some legal gray area in which snippets of commercial copyrighted code could arguably be posted verbatim on this site for educational purposes.  Schools do this with literature all the time.  As long as it is obvious that no commercial harm is intended, via the gathering of profit from someone else's copyrighted work, it is unlikely that anyone could successfully sue Alex for copyright infringement.  And as long as the actual source organization or person's name is not posted, a defamation/libel/slander suit is not likely to get far either.  That would be my opinion, but IANAL, and IANA (I Am Not Alex).  :)


    savar:


    Second rule: nobody here should make fun of other people's code if they don't truly understand what is going on. There are a lot of opinions here about how to properly do money math -- only a couple people are correct. And yes, there is such a thing as "correct" -- it is mandated by law and industry standards. If you work for a large financial corporation, then money math is ALWAYS DONE IN DECIMAL.


    This is a very good point as well, and not enough software developers (or those who call themselves software architects) understand it.  Or the related point that the number of significant digits in a fractional calculation is a well-defined quantity, and having too many digits is just as wrong as having too few.  I would say that part of the blame for this lies in mathematics and computer science degree programs which completely avoid dealing with real-world issues such as money math and significant figure calculations, and sometimes only barely touch on the pitfalls of binary floating point arithmetic.
      You don't need to know about these areas to get a degree, but you will surely need them if you want to be able to write correct real-world code.

  • (cs) in reply to csrster

    Anonymous:
    Anonymous:
    Ok, so the code sucks.

    And it doesn't take into account some obvious cases ($0.00 is mentioned above).

    But this sounds like you are presuming that money is always done in floating point, when in fact, using fixed point decimal (ok, so this doesn't really do that either), and representing the numbers as integers, is generally much simpler.  Depending on your integer math implementation (does it round?) you can avoid things like "$0.9999999999999999999" etc.

    There seem to be plenty of reasons to dismiss this code as WTF without attacking the idea of integer money.


    Funnily enough, there was a thread on slashdot yesterday on the very subject of types for representing money.

    Reading threads involving money on this site are quite funny, like nobody here has ever had to work with an accounting department!  They have this book, you see, called the GAAP.  It is the 'accounting bible' so to speak.  Go to your accounting department, you will find it on a bookshelf.  In the GAAP you will find documentation about dealing with money in computer systems.  Money is to be stored in 4 decimal place amounts ($1.1234) and during transactions rounded to two decimal places according to something called 'banker's rounding' which specifies that .5 is rounded towards the nearest even number.  $1.3550 becomes $1.36 and $1.3450 becomes $1.34 (the reasons for this are obvious when millions of transactions are considered).

    Point is you CAN'T store money in a FLOAT!  It's against the law!  Unless your ENRON of course, then you just pencil in whatevor numbers you fancy.

    SQL Server has a nice 'MONEY' data type to take care of this for you.

    It's also interesting to note that other countries have different requirements for this ... I'm just going buy my own experiences.

  • Anonymous Coward (unregistered) in reply to Bus Raker
    Bus Raker:

    Anonymous:
    Anonymous:
    Ok, so the code sucks.

    And it doesn't take into account some obvious cases ($0.00 is mentioned above).

    But this sounds like you are presuming that money is always done in floating point, when in fact, using fixed point decimal (ok, so this doesn't really do that either), and representing the numbers as integers, is generally much simpler.  Depending on your integer math implementation (does it round?) you can avoid things like "$0.9999999999999999999" etc.

    There seem to be plenty of reasons to dismiss this code as WTF without attacking the idea of integer money.


    Funnily enough, there was a thread on slashdot yesterday on the very subject of types for representing money.

    Reading threads involving money on this site are quite funny, like nobody here has ever had to work with an accounting department!  They have this book, you see, called the GAAP.  It is the 'accounting bible' so to speak.  Go to your accounting department, you will find it on a bookshelf.  In the GAAP you will find documentation about dealing with money in computer systems.  Money is to be stored in 4 decimal place amounts ($1.1234) and during transactions rounded to two decimal places according to something called 'banker's rounding' which specifies that .5 is rounded towards the nearest even number.  $1.3550 becomes $1.36 and $1.3450 becomes $1.34 (the reasons for this are obvious when millions of transactions are considered).

    Point is you CAN'T store money in a FLOAT!  It's against the law!  Unless your ENRON of course, then you just pencil in whatevor numbers you fancy.

    SQL Server has a nice 'MONEY' data type to take care of this for you.

    It's also interesting to note that other countries have different requirements for this ... I'm just going buy my own experiences.



    Umm... No. The GAAP is NOT a law. It's a set of standards published by the FASB. No private company is required to follow it. Private companies could have a chimpanzee do their accounting by simulating floating point arithmetic using rocks and sticks, rounding at 42 decimal places to the nearest odd value, but only on Wednesdays when the chimp isn't "in the mood".

    Public companies and government agencies, on the other hand, might be required to adhere to GAAP. Not sure.... seems to me, that would be imposed by the SEC or some similar organization.

    OT: Hey! Even backspace causes 2 new javascript errors! WTF?
  • (cs) in reply to bool-man
    bool-man:
    Anonymous:
    You know, computers use binary. Wouldn't it be much better to get rid of all datatypes except for booleans?
    Anyone remember:

    enum Bool {
    TRUE,
    FALSE,
    FILE_NOT_FOUND
    };

    ???



    No.

  • Matthew (unregistered) in reply to Anon

    Unix Epoch Time? Nah... Who would ever use THAT?

     

    CATPCHA: Whiskey, the kind the coders musta been drinking.

  • Boo Boo (unregistered) in reply to exussum

    Anonymous:
    It's standard practice to represent floats/decimals in integer form. Otherwise you get funky rounding things happening when you multiply or divide. It's just a fact of life. It gets worse in finance, as some things go to 32'nds and beyond and you are using a large value to begin with. Soo... typically you'd do everything in integer/long form and display it in float/decimal form to minimize the damage by using String manipulation. No, finance people do not like it when numbers get botched out of their control. :)

    Yes, I see!  So instead of 1.10, I store the number as 110.  Now we're safe!  I can just put that decimal back at any time.  Nothing "funky" could possibly happen to this pure integer now. :)

    Now, playing the role of the finance type, I divide this number up into three parts because I'm allocating 110 into 3 business units.  They're both integers, so no prob here.  I'll just.....

    110 / 3 = 36.666666666666666666666666666667

    Uhhh.  Wait a sec.  What the PAULA just happened to my pure non-funky integer?  I just divided, and....

    Let's put that decimal back (though I already have one), sweep it back into the database, and pretend this never happened.

    THIS MESSAGE IS "G4" CLASSIFIED.

  • (cs) in reply to Boo Boo
    Anonymous:

    Anonymous:
    It's standard practice to represent floats/decimals in integer form. Otherwise you get funky rounding things happening when you multiply or divide. It's just a fact of life. It gets worse in finance, as some things go to 32'nds and beyond and you are using a large value to begin with. Soo... typically you'd do everything in integer/long form and display it in float/decimal form to minimize the damage by using String manipulation. No, finance people do not like it when numbers get botched out of their control. :)

    Yes, I see!  So instead of 1.10, I store the number as 110.  Now we're safe!  I can just put that decimal back at any time.  Nothing "funky" could possibly happen to this pure integer now. :)

    Now, playing the role of the finance type, I divide this number up into three parts because I'm allocating 110 into 3 business units.  They're both integers, so no prob here.  I'll just.....

    110 / 3 = 36.666666666666666666666666666667

    Uhhh.  Wait a sec.  What the PAULA just happened to my pure non-funky integer?  I just divided, and....

    Let's put that decimal back (though I already have one), sweep it back into the database, and pretend this never happened.

    THIS MESSAGE IS "G4" CLASSIFIED.



    If you responded to this thread, and have never read the below link, you probably said something completely retarded.

    <font><font color="#003366" face="Verdana, Arial, Helvetica, sans-serif">What Every Computer Scientist Should Know About Floating-Point Arithmetic</font></font>

    http://docs.sun.com/source/806-3568/ncg_goldberg.html
  • Doh (unregistered) in reply to Boo Boo
    Anonymous:
    Yes, I see!  So instead of 1.10, I store the number as 110.  Now we're safe!  I can just put that decimal back at any time.  Nothing "funky" could possibly happen to this pure integer now. :)

    Now, playing the role of the finance type, I divide this number up into three parts because I'm allocating 110 into 3 business units.  They're both integers, so no prob here.  I'll just.....

    110 / 3 = 36.666666666666666666666666666667

    Uhhh.  Wait a sec.  What the PAULA just happened to my pure non-funky integer?  I just divided, and....

    Actually, given our example is in C#:

    <font face="Courier New" size="2">110 / 3 = 36</font>

    Unless, of course, you meant:

    <font face="Courier New" size="2">110 / (float) 3 = 36.66667</font>

    or:

    <font face="Courier New" size="2">110 / (double) 3 = 36.6666666666667</font>

    or:

    <font face="Courier New" size="2">110 / (decimal) 3 = 36.666666666666666666666666667</font>

    All of which, given that the "real world" value was being stored in "cents" in an int, would give the same results when put back into the system: 36 cents. It's true that you've lost a penny, but when you only chose a precision of whole pennies, what did you expect?

    If the decimal datatype did not already exist, and no one had yet developed BCD, it would be quite reasonable to use a "shifted" int value....just make sure you "shift" it to the precision you want (most accounting uses four digits after the decimal point, so shift your int by four places (multiply by 10000)). In this case, dividing 11000 by 3 only results in the loss of $0.0001, which will be acceptable in almost any situation.

    CAPTCHA = hotdog
  • Adam (unregistered) in reply to its me
    its me:
    I guess booleans and datetimes are just for suckers. I mean who would ever want to subtract or add dates, or set a series of properties to the same boolean value....

    Gotta wonder how far it went, were enum's banned? Structures?

    You also gotta wonder how they enforced this pile of steaming waste, it's not like you can just remove standard value types from .Net....

    -Me


    My guess is that dates are represented as the number of seconds since a predefined date. Except second may not be fine-grained enough. They probably represent it as a number of miliseconds.
  • (cs) in reply to Anonymous Coward
    Anonymous:


    Umm... No. The GAAP is NOT a law. It's a set of standards published by the FASB. No private company is required to follow it. Private companies could have a chimpanzee do their accounting by simulating floating point arithmetic using rocks and sticks, rounding at 42 decimal places to the nearest odd value, but only on Wednesdays when the chimp isn't "in the mood".

    Public companies and government agencies, on the other hand, might be required to adhere to GAAP. Not sure.... seems to me, that would be imposed by the SEC or some similar organization.

    OT: Hey! Even backspace causes 2 new javascript errors! WTF?


    GAAP is enforced by the SEC. Private companies -- I would imagine -- declare similar adherence to such standards in order to get people to invest in them...it would be quite foolish to give money to somebody who had no standards of accounting for it.
  • hk0 (unregistered) in reply to Jesus Christ

    Jesus christ it's a lion get in the car!

  • 4chan (unregistered) in reply to Doh

    Exactly. In many cases your system will work with explicit dollars and cents quantities only. When calculating interest, you convert your interest rate thusly:

    1.015% = >101015

    Multiply your prinicpal by the adjusted value, then integer divide by 1000.
    This will leave your quantity with two extra decimal places of precision.
    Now apply standard accounting rounding (0-49 down, 50-99 up), then divide by 100 to get back to your base units (whole cents).

    The same procedure can be used with fractional cents as the base unit.

    Using 64-bit in memory representations you can precisely handle very large amounts in this fashion.

  • (cs) in reply to RichNFamous
    Anonymous:
    Anonymous:
    Anonymous:
    Well that's great, that's just fuckin' great man. Now what the fuck are we supposed to do? We're in some real pretty shit now man... That's it man, game over man, game over! What the fuck are we gonna do now? What are we gonna do?


    Nice quote from Aliens, weird nobody else commented before?


    Alien, not Aliens, puhleeze!


    SORRY, It was definitely Aliens, as in the 2nd movie of the series. You know, the one with the marines. Not the first one, with the all time great shot of the alien popping out the the guys chest while everyone's sitting at the table eating breakfast.

    Get it right, or be relegated to being a WTF yourself.


  • (cs) in reply to snoofle
    snoofle:
    You're not thinking enterprisey-enough. There are no negative numbers. Only integers >= Zero are "real" numbers. If you want to use negative numbers, you have to use the NegativeNumber wrapper object, with it's all-XML implementation:
    <number><NegativeNumber>
    <SIGN>-</SIGN>
    <DIGIT>1</DIGIT>
    <DIGIT>2</DIGIT>
    <...></number>
    </NegativeNumber>
    Unfortunately, some people don't realize that the order of XML elements can be deemed significant.  Some would insist on this instead looking like this:
    <Number>
    <ThousandsDigit>1</ThousandsDigit>
    <HundredsDigit>2</HundredsDigit>
    ....
    </Number>
    Similarly, I once saw someone try to specify hierarchical set of data in XML like this:
    <Foo1 value="a">
    <Foo2 value="b">
    <Foo3 value="c"/>
    </Foo2>
    <Foo2 value="d"/>
    </Foo1>
    Each<font face="Courier New" size="2"> Foo* </font>element was identical except in name, and the number on it identified the depth of the element.
  • (cs) in reply to 4chan
    Anonymous:

    Now apply standard accounting rounding (0-49 down, 50-99 up), then divide by 100 to get back to your base units (whole cents).


    Accountants use banker's rounding.
  • fixed point math isn't exactly unheard of (unregistered) in reply to ChiefCrazyTalk

    on many platforms floating point simply doesn't exist.  celphones, nintendo ds - anything with an arm-processor on it.

    nothing very strange about this - and yes you can do division, multiplication - as well as any kind of advanced math (sin/cos/tan etc) on fixed point processors perfectly fine.

  • (cs)

    Now I can write Perl in any .NET language.

Leave a comment on “Enterprise Beautification”

Log In or post as a guest

Replying to comment #:

« Return to Article