views:

108

answers:

2

A friend asked me to update his shopping cart software. It's written in classical ASP using IE's JScript. I can't seem to format the variables correctly.

. <% if (oOrder['product'] == "camera") 
{ %> <%= format_float(oOrder['cost'], 2, 3)/2 %> <% } %> 
            %>

When I do this I get a bunch of jibberish with regards to the output. I'm guessing it's because of a datatype mismatch.

I get -1.#IND as the output.

+4  A: 

What does format_float do, and what does it return? I suspect it is returning a formatted string, in which case you need to divide first, like this:

<%= format_float(oOrder['cost']/2, 2, 3) %>

But you still need a way to parse oOrder['cost'] if it is a string and format_float is not doing it.

Robert Harvey
@Robert: I didn't know classic ASP 1/2.0 support server-side jscript, so you really think it's the `format_float` causing the problem and not the entire syntax?
o.k.w
Is that what this is, jscript? I haven't a clue about jscript.
Robert Harvey
Classic ASP rides on top of VBScript (at least the syntax is), seeing `[ ] { } ==` on a ASP server-side script really confuses me.
o.k.w
Don't be confused, JScript for ASP is IMHO a far better language to use. Its structured and so much nicer to write and read when done well :)
Pete Duncanson
+3  A: 

Here is how the code ought to be structured:-

<%
   if (oOrder.product == "camera")
   {
      Response.Write(format_float(order.cost / 2, 2, 3)); 
   }
%>

Try to avoid closing and opening default script tags %> <% when you have no actual HTML markup inbetween.

AnthonyWJones
@AnonJr: Robert has already provided the answer. Didn't seem much point repeating it.
AnthonyWJones
Sorry, too much blood in my caffeine system... Didn't notice that you used the code from Robert's answer.
AnonJr