- Feature Articles
-
CodeSOD
- Most Recent Articles
- What a More And
- Hall of Mirrors
- Magical Bytes
- Contact Us
- Plugin Acrobatics
- Recursive Search
- Objectified
- Secondary Waits
- 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
Unix timestamps are accurate to the second.
Sometimes you need to ensure uniqueness of a date, not a second in time. Storing dates in this format YYYYMMDD is pretty straightforward, compact, and allows for easy, portable constraints to ensure the uniqueness of a specific date.
// THIS IS NOT A WTF //
The WTF is the convoluted way that the poster described the date format, as though "YYYYMMDD" wasn't somehow easier to recognize...
Admin
I guess nobody ever heard of a mill.
Look, I've restrained myself. I swore I would read all the responses before posting..
there's NO WTF here.
Convert $2.49 to pennies by stripping out the "$", and ".".
If its $15,249.49, yeah, strip out the the ",".
if its 15259.5 (like data from *nix systems), parse it.
That's why they're paying you the bucks.
If the the date plus 10 overflows, parse it. Fix it.
Any C programmer could do this with both eyes and asshole closed.
The rest of you script kiddies, get a life!!!!!
Admin
And adding 15% ?
pennies = (pennies*115)/100
Don't make me puke!
Admin
The real money is to made in jobs that don't involve "Accounting".
Admin
from den Bosch:
The real WTF is this forum software.
Of course, we've heard this many times before.
But, consider. . .
One opens the forum, somewhere past "First" post.
Possibly past the first 50 posts.
Hmmm... Something perhaps worthy of a reply.
reply is made. . .
Captcha isn't valid. OK. The dinky thing on the bottom of the screen has timed out. Fair enough (but, solveable by software).
But, when the entry IS accepted, one is kicked back to the original highest-level for that date. Dumb, dumb, software, doesn't know to bring you back were you where when your now-interrupted train-of-thought let you to make a comment.
Not to mention that registering and/or putting in your real name leads to a lifetime supply of V*agr*a Sp*m
SSUUCCKKSS!!
Admin
Consider the Gas Companies, who charge at rates of n.nnnn per cubic meter of gas. Conversion to (your unit of choice), in integers or longs (depending on your system, definitely not a float), makes the math much more accurate.
Certainly more accurate than an Excel spreadshit. . . Ooops I guess that's why they paid me to fix the problem.
Admin
I'm waiting for the phone call from the guy who says I owe $0.00
lol, comkb
Admin
Hello?
January, 1970 + 2^32 is sometime in 2038.
It'll make Y2K look like a tea-party.
Admin
That's just plain Stupid
Admin
I should have read further. . . but, as someone once said, once the seal has been broken. . .
Admin
Actually, "08" is a string.
Almost sincerely. . .
Admin
The real wtf is that so many of the people who post on here have no clue.
I simply cannot believe today's discussion.
Most of you monkeys don't even know why today's wtf is a wtf... but you think you do - and post comments that expose you as a clumsy operator.
If you don't really understand today's wtf like so many of today's posters, you really need to go back to school.
Well done guys, keep the wtf comments coming, they always make us cringe more than the original post!
Admin
Let's hear it for the Pope!
Admin
IBM has something called the "telco benchmark", where you have to add up price, tax, and tariff for a million phone calls. All results have to be correct to the cent (I suppose they did the calculations with rational arithmetic to get the exact values). If you use standard floating point arithmetic, you can be as much as $20 off.
Major long-distance companies go through that many calls in a couple minutes.
Go puke.
Admin
Oh man.
I once worked somewhere where almost all money calculations were done in Excel, even by the "programmers" in my department.
One day, one of the guys had summed a column and he was puzzled as to why it didn't total up to what it was supposed to.
I told him that it was because Excel used floating-point numbers. Of course, because he had zero formal training in CS, he had no idea what a floating point number. Since he was supposed to be some sort of superstar dude, I left him to his own devices.
To this day, he still doesn't get it. At the very least, he could multiply his column values by 100, sum them, and then divide the total by 100. But he was never "superstar" enough to figure that out.
Admin
Admin
If you are worried about the inaccuracy of float or double, DBMS vendors are too, and that's why they often provide a decimal or money datatype which while a little more spacey does the computations in the right way.
Admin
This is a WTF as well. The whole floats have a mind of their own blah, and tripping up floats bullsh*t... It's a programming language, it works the way it was designed to, you can't trip it up, and it doesn't have a mind.
This person first explains how floats work, and then says never to use them because floor() might lead to unexpected results. Yeah, and dividing an int by 0 will lead to strange results as well, so best not use ints, they can be 'tripped up'. If you can't cook, stay out of the kitchen...
Admin
I'm almost crying with laughter at this. The guy is spot on.
Admin
My #1 WTF sofar... Unbelievable.....
Admin
[N]
Is the word "consultant" somewhat abused here?
Consultant: "one who gives professional advice or services". If your company hires non-consultant problematic would-be code hackers, go see your boss and convince him he was wrong. He should hire more employees who clean messy systems!
More questions I have when reading susch stuff:
Are consultants just out there to assure jobs for employees by creating messy systems?
Would employees on their own be able to even start creating such a mess?
[B]
Admin
There are always pros and cons.
Admin
What's wrong with using the stored datatypes that come with your database.
You ca't avoid rounding problems, of fractional numbers in a computer system. Never! (within reason)
Not even when you try to reimplement a solution for it using only ints. It's bullshit and while you're solving one problem, you're introducing tons of other problems.
Admin
In that circumstance, I would send the payment immediately. In cash.
Admin
Cons are usually brought in as wearing double cuffs and cuff links adds more weight to your coding.
Seriously tho, just use money data types and use a decent machine to serve from.
Admin
He's wrong, anyway. "Cliche" is quite acceptable as an adjective in English, and it's obvious why if you know the French. I wish people wouldn't bitch about grammar when they are clueless.
Admin
Um, not programatically (IME anyway). The extra's just get trimmed.
Admin
Just like that apostrophe that sneaked in to my post should be trimmed.
Admin
Joe Celko has a nice line on developers and floats:
The moron that declared columns to be FLOAT in a commercial system is probably a C programmer who does not understand rounding errors.
http://www.intelligententerprise.com/000626/celko.jhtml
Admin
First, that is false. I work in assembly language. It's not "more resource-intensive".
On the second, Epsilon value is used not to minimize, but to eliminate completely errors. As it's been pointed out, putting 0.1 * 0.1 in the explorer direction bar returns a value of 0.0100000......00000020 That would fail to test against 0.01 but it's enough close. That's Epsilon for. If you know the limits of your floating point unit, no problem. And that leads me to say, how can 0.00000000000000000000000000000x prevent a 2 decimal number from being calculated with correctness? (And don't tell there are a zillion values of that form in bank transactions as that would be the necessary distinct values needed to fool the calculation)
And actually, the precission that a float can give (remember, no doubles in 3d engines) is enough for all purposes.
Admin
Non-portable to countries that don't use the dollar - think of the amount of work required for each country 1,$s/DOLLAR/EURO/g etc.
However, if it had been called CENTS, at least it could be used in the Euro zone, or call it PENNIES and you can use it in the UK. :)
Or CENTS_OR_PENNIES_OR_SIMILAR and you can use it anywhere. :)
And you may tip 15%, but this side of the pond we are too mean, make that 15percent_or_5percent_if_british
Admin
Heh, you're just trying to trick people to tell you exactly why this WTF _is_ a WTF, 'cause you just have no clue ;)
(Smiley should be enough, shouldn't it... Right? RIGHT??? WTF...)
Admin
Just seeing his name makes stuff like 'fields are not columns' going through my head...
Admin
So it doesn't bother you if your bank is unable to represent the amount $0.1?
Never ever write code fort me. Please!
You use epsilon to provide a range within which you assume "it's good enough". It might be, or it might not be. You have no guarantee, and moreover, it only helps you with comparisons.
It does not magically allow you to represent numbers that can't be represented as floats (such as 0.1). It does not allow you to multiply 0.0001 with 0.0001 and get a nonzero value. It does not, in fact, solve the problems with floating point numbers!
Yes you can. If you know what you're doing.
Rounding errors *only* occur with floating point datatypes. Integer datatypes have limited precision, yes, but that's something entirely different. For one thing, they're predictable. You usually know how many decimals you need for the operations you need to perform on the data you're operating with. And then you can easily choose a fixed point that suits your needs.
Or you could just make your own datatype with dynamic lenght, to make sure you can represent any number at any precision.
But for representing money, a simple integer datatype works fine. You only have a set number of decimals, no matter what you do. And the final result is always rounded to a fixed (and small) number of decimals, so it's pretty easy to guarantee precision.
This thread has scared the life out of me. If the people reading *this* site of all things, can't tell the difference between a float and an int, the world is a scary place.
The "real" WTF is that so many people here would prefer to use floating point datatypes for money, or that they're arguing that "You can't avoid precision loss", or "It doesn't matter with a few small rounding errors".
That is just scary. Really really scary. Please tell me if any of you get any contracts in my part of the world. If you do, I'm moving.
Admin
The real WTF is that IT'S A CONTRACTION!
Admin
While I agree that SQL Server *should* have a "date only" datatype, that is no reason to do something like this. It is extremely easy to add a simple constraint to a table to be sure that dates only are stored (i.e., the time is always 12:00:00 AM). Then you have not reinvented the wheel, you are guaranteed that your data is valid, and you can perform date math and formatting on the data without conversions, and so on.
Your data has absolutely no integrity if you use a hacked solution like this. The only conceivable way you might get away with this and still have valid data would be to create a table of all Dates you need to cover and reference it is a FK. Then, that table will ensure that your dates are valid, and you can add entries in that table to provide "date math" features (i.e., day, month, year, dateTime equivalent, etc). But that would not be too smart since now your dates become *entities* as opposed to attributes, and I doubt they need to be.
Admin
unrelated comment:
I hate gettext on php por no purpose.
related comment:
If you really care about money as float. Maybe can be a working solution to make a "BCD class" to work with money as strings of decimal numbers. This can be a good idea if you work with a strong type lang. I will love to see one for Javascript, because Math on javascript live somewhere on Mondo Bizarro
cheat card for webmasters:
Float (a lossy format) = JPG
Integer (lossless) = GIF
Admin
http://www2.hursley.ibm.com/decimal/decifaq.html
Thats a good read.
Admin
Needs to be put in the KITCHEN:
[:S]
The HEN (Holistic Enterprise Namespace) can be created by using EGGs:
[*-)]
Just don't let the "firefox" in the hen house.
[+o(]
Admin
Would not "0.0115 AS INT" equate to zero?
Admin
Would not the @retvalue always be zero? 0.0115 AS INT should evaluate to zero, right?
Admin
Or better yer, store a picture of the item in the DB as a gif, and use steganography to embed the price right into the image, thus saving valuable disk space.
Now if only I can find a way to obfuscate the encryption function ...
... if only ....
Terry
Admin
What on earth were the consultants thinking.I can not figure a single instance where something like this is useful :|
Admin
What if the %age rate changes ... ? [8-|]
Admin
A team of cheap programmers in Outsourcelandia will write functions or all percentage rates from 0 to 100.
The border cases 0% and 100% will make it to the front page of TDWTF, because they follow the same pattern like the other functions, which looks even dumber for 0%.
Admin
How does the HP-12C does its calculations? I'm surprised no one mentioned the 12C yet; in two of my previous jobs the "customer" would always consult the 12C to verify if the result of any monetary calculation was "correct".
Admin
Hmm. I read how they did the date (leads to the number 20060426) and thought, "Hey! Cool idea!" ... Is that a bad sign? Really, is that so bad, for storing an 8 digits of a date value?
Admin
Admin
Really, is that so bad, for storing an 8 digits of a date value?
---
reply:
20060231
--Tei
captcha: screen
Admin
what happened in office space was different than superman 3.
those stories have nothing to do with one another.