Click here to Skip to main content
15,885,869 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

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. All actual programming questions will be removed.

 
GeneralRe: How To Use Session Variables Pin
Member 882490521-Jun-13 3:28
Member 882490521-Jun-13 3:28 
GeneralRe: How To Use Session Variables Pin
AnalogNerd21-Jun-13 4:01
AnalogNerd21-Jun-13 4:01 
GeneralA Brilliant Replacement of float.toFixed(2) Pin
TNCaver17-Jun-13 9:25
TNCaver17-Jun-13 9:25 
GeneralRe: A Brilliant Replacement of float.toFixed(2) Pin
LloydA11117-Jun-13 9:33
LloydA11117-Jun-13 9:33 
GeneralRe: A Brilliant Replacement of float.toFixed(2) Pin
Marc Clifton18-Jun-13 5:30
mvaMarc Clifton18-Jun-13 5:30 
GeneralRe: A Brilliant Replacement of float.toFixed(2) Pin
AlphaDeltaTheta18-Jun-13 17:17
AlphaDeltaTheta18-Jun-13 17:17 
GeneralRe: A Brilliant Replacement of float.toFixed(2) Pin
Brisingr Aerowing19-Jun-13 3:08
professionalBrisingr Aerowing19-Jun-13 3:08 
GeneralRe: A Brilliant Replacement of float.toFixed(2) Pin
TNCaver20-Jun-13 5:06
TNCaver20-Jun-13 5:06 
The second line handles NaN.

How extensive were your tests in W3Schools Try It? The code in question ran in production for a few years, and it runs flawlessly 99.99% of the time. But that 0.01% where it didn't is why I was looking into it.

My point is this: the amount of time needed to write and test that convoluted mass of spaghetti, and to understand and troubleshoot it later, is unacceptable when a simple solution is built-in and readily available.

If he didn't know about toFixed() is not much of an excuse; one should know your tools, or at least know how Google works.

You still need a solution that catches NaN, so it makes sense to wrap isFixed in a function:

JavaScript
function CurrencyFormatted(amount) {
	var i = parseFloat(amount);
	if (isNaN(i)) { i = 0.00; }
	return i.toFixed(2);
}

If you think 'goto' is evil, try writing an Assembly program without JMP.

GeneralRe: A Brilliant Replacement of float.toFixed(2) Pin
Bob100020-Jun-13 4:46
professionalBob100020-Jun-13 4:46 
GeneralRe: A Brilliant Replacement of float.toFixed(2) Pin
TNCaver20-Jun-13 5:12
TNCaver20-Jun-13 5:12 
GeneralDatetimes in java (again) Pin
V.13-Jun-13 1:22
professionalV.13-Jun-13 1:22 
GeneralRe: Datetimes in java (again) Pin
BotCar13-Jun-13 1:38
BotCar13-Jun-13 1:38 
GeneralRe: Datetimes in java (again) Pin
Brisingr Aerowing13-Jun-13 2:58
professionalBrisingr Aerowing13-Jun-13 2:58 
GeneralRe: Datetimes in java (again) Pin
Rob Grainger18-Jun-13 1:00
Rob Grainger18-Jun-13 1:00 
QuestionMessage Closed Pin
12-Jun-13 21:44
User 1006066512-Jun-13 21:44 
AnswerRe: HTML 5 Application. Pin
AlphaDeltaTheta12-Jun-13 21:53
AlphaDeltaTheta12-Jun-13 21:53 
GeneralMessage Closed Pin
12-Jun-13 21:57
User 1006066512-Jun-13 21:57 
GeneralRe: HTML 5 Application. Pin
AlphaDeltaTheta12-Jun-13 22:02
AlphaDeltaTheta12-Jun-13 22:02 
GeneralRe: HTML 5 Application. Pin
User 1006066512-Jun-13 22:16
User 1006066512-Jun-13 22:16 
GeneralRe: HTML 5 Application. Pin
AlphaDeltaTheta12-Jun-13 22:21
AlphaDeltaTheta12-Jun-13 22:21 
GeneralMessage Closed Pin
12-Jun-13 22:24
User 1006066512-Jun-13 22:24 
GeneralRe: HTML 5 Application. Pin
AlphaDeltaTheta12-Jun-13 22:32
AlphaDeltaTheta12-Jun-13 22:32 
JokeRe: HTML 5 Application. Pin
jim lahey17-Jun-13 10:15
jim lahey17-Jun-13 10:15 
AnswerRe: HTML 5 Application. Pin
AlphaDeltaTheta18-Jun-13 17:09
AlphaDeltaTheta18-Jun-13 17:09 
GeneralBug of the Day (2) PinPopular
Rob Grainger12-Jun-13 4:47
Rob Grainger12-Jun-13 4:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.