开发者

Formatting floating point numbers in ASP

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 guess开发者_开发问答ing it's because of a datatype mismatch.

I get -1.#IND as the output.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜