 |

|
I'm re-writing a legacy ASP application. There's an expensive call to an external webservice and a database to determine a calculated setting specific to the person logged in.
On the first page this calculation is done and the result is stored in a session variable.
On every subsequent page the session variable is ignore, the value is recalculated and then stored in the session variable again!
Some days I don't know if to laugh or cry.
|
|
|
|

|
Sometimes, you just want to go into a code review with a baseball bat and a spiked glove...
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|

|
Our finance folks were a bit annoyed by one of our web pages, where it occasionally rounded the final total to the nearest dime. While troubleshooting a former colleague's JavaScript code that added 2% to the amount entered by the user, I found this gem. His intention, at least, was obvious by the function name.
function CurrencyFormatted(amount) {
var i = parseFloat(amount);
if (isNaN(i)) { i = 0.00; }
var minus = '';
if (i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if (s.indexOf('.') < 0) { s += '.00'; }
if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}
Isn't that brilliant? I mean, why use the simple, single-line solution isFixed(2) when you can do the same thing in 9 lines?
If you think 'goto' is evil, try writing an Assembly program without JMP.
modified yesterday.
|
|
|
|

|
Perhaps he didn't know isFixed exists
.-.
|o,o|
,| _\=/_ .-""-.
||/_/_\_\ /[] _ _\
|_/|(_)|\\ _|_o_LII|_
\._. |\_/|"` |_| ==== |_|
|_|_| ||" || ||
|-|-| ||LI o ||
|_|_| ||'----'||
/_/ \_\ /__| |__\
|
|
|
|

|
Well, perhaps toFixed doesn't work the way he wanted?
Does it handle NaN?
Does it do rounding?
Does it round the absolute value of the value (which would always round up, right?)
Goofing around with the W3School's Try It[^] feature (snazzy) I think everything works correctly except the NaN handling.
Marc
|
|
|
|

|
Marc Clifton wrote: Does it handle NaN?
I don't think NaN will ever arise while currency formatting (going as per method name), without exceptions. He's not doing tan 90 anywhere is he?
|
|
|
|

|
GregorianCalendar date = new GregorianCalendar(1888, 0, 1, 0, 0, 0);
SimpleDateFormat sdf = new SimpleDateFormat("YYYY");
String convertedstring = sdf.format(date.getTime());
System.out.println(convertedstring);
output: 1887 (on my laptop anayway)
GregorianCalendar date = new GregorianCalendar(1888, 0, 1, 0, 0, 0);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
String convertedstring = sdf.format(date.getTime());
System.out.println(convertedstring);
output: 1888
For those who didn't notice, in sample 1 I put "YYYY", in sample 2 "yyyy".
I couldn’t immediately find something in the docs or google explaining this…
|
|
|
|

|
"YYYY" means week years.
Quote: A week year is in sync with a WEEK_OF_YEAR cycle. All weeks between the first and last weeks (inclusive) have the same week year value. Therefore, the first and last days of a week year may have different calendar year values.
For example, January 1, 1998 is a Thursday. If getFirstDayOfWeek() is MONDAY and getMinimalDaysInFirstWeek() is 4 (ISO 8601 standard compatible setting), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. The week year is 1998 for the last three days of calendar year 1997. If, however, getFirstDayOfWeek() is SUNDAY, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997 and their week year is 1997
SimpleDateFormat[^]
GregorianCalendar[^]
|
|
|
|

|
Quite odd, that is.
Gryphons Are Awesome! Gryphons Are Awesome!
|
|
|
|

|
Unfortunately, many human systems for dealing with dates are odd, all computers can do is reflect that.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
 |
Message Automatically Removed
|
|
|
|

|
An application that presents it's UI in html5 and runs in a browser as a regular webpage. Leveraging html5 technoligies, it can do pretty much the same thing that a standard user level application does... Like a word processor. Anyways Let me google that for you![^]
But don't tell about a disk defragmanter HTML5 App!
You're new, please read the announcement at the top, this ain't the right place for asking questions...
|
|
|
|
|

|
Draw.IO[^]
Remember...
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.
|
|
|
|

|
OK... But I have more questions about this topic...
What should I do
-Toywarrior
|
|
|
|

|
We've got programming forums here in CP, see Discussions > Web Developments
|
|
|
|

|
Will You Join me There????
-Toywarrior
|
|
|
|

|
If you post then... if I get you
|
|
|
|

|
Looks like you've pulled
|
|
|
|

|
He was a first timer... little lax was on my part
|
|
|
|

|
I can beat that - I discovered a bug where new records were failing to be added.
After a number of false trails, I homed in on the following SQL user function:
ALTER function [dbo].[ufn_GetNextID](@IDTable as varchar(100), @IDColumn as varchar(100))
returns integer
as
begin
declare @NewID as integer
set @NewID=0
return @NewID
end
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|

|
Gryphons Are Awesome! Gryphons Are Awesome!
|
|
|
|

|
I don't see anything wrong there, what does "0" mean anyway?
|
|
|
|

|
richcb wrote: what does "0" mean anyway?
I believe its the shape of my mouth every time I come across examples like this!
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|

|
Nice, that had me rollin for a minute!
|
|
|
|
 |