指定一个变量的小数位在一个字符串 [英] Specifying decimal places on a variable in a string

查看:134
本文介绍了指定一个变量的小数位在一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先简单后找了几个小时,我看我的问题多解决方案,但我在努力加以落实,并希望有人能够帮助一个noob。

after briefly looking for a few hours I see multiple solutions to my problem but I am struggling to implement them and hopefully someone can help a noob.

问题是,我有一个下拉在错误地显示了一些价格的ASP / MySQL的Web应用程序框。例如,如果数据是32.00显示的数字将返回为32,同样,如果6.50它显示为6.5数据类型或价格被设置为十进制在db表(19,2)的长度,而且价格显示正确别处除了在一个下拉框中显示的选项这一个实例。
我是pretty一定有一个简单的办法,并会真的AP preciate修复。我以为我可以添加.toFixed(2),所以实际上它像该<(%)= DealCartsDB(价格)toFixed(2)%>,但它说的不支持。

The issue is that I have a drop down box in an ASP/MySQL web application that displays a few prices incorrectly. e.g if the data is 32.00 the figure displayed will be returned as 32, similarly if it 6.50 it displays as 6.5 The data type or the price is set to Decimal(19,2) length in the db table, and the price shows correctly elsewhere except in this one instance of options displayed in a drop down box. I am pretty certain there is an easy fix and would really appreciate a fix. I thought I could add .toFixed(2) , so in effect it was like this <%=DealCartsDB("price").toFixed(2)%>, but it say's not supported.

<select name="deal" class="qty" onChange="swapDeal()">
<option value="-1">CHOOSE YOUR DEAL</option>
<% while not DealCartsDB.Eof %>
<option value="<%=DealCartsDB("dealid")%>"<% if clng(dealID)=DealCartsDB("dealid") then %> selected<% end if %>><%=DealCartsDB("dealname")%>........&pound;<%=DealCartsDB("price")%></option>
<% DealCartsDB.MoveNextWend %></select>

任何帮助非常AP preciated,谢谢你。

Any help much appreciated, thank you.

推荐答案

试试这个:

<%= FormatNumber(DealCartsDB("price"), 2) %>

这篇关于指定一个变量的小数位在一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆