简体   繁体   English

在ASP中格式化浮点数

[英]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. 它是使用IE的JScript以经典ASP编写的。 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. 我得到-1.#IND作为输出。

What does format_float do, and what does it return? format_float是做什么的,它返回什么? 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. 但是,如果oOrder ['cost']是字符串并且format_float没有执行此操作,则仍然需要解析oOrder ['cost']的方法。

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. 当您之间没有实际的HTML标记时,请尝试避免关闭和打开默认脚本标记%> <%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM