Specifying decimal places on a variable in a string

好久不见. 提交于 2019-12-08 00:27:39

问题


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.

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>

Any help much appreciated, thank you.


回答1:


Try this:

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


来源:https://stackoverflow.com/questions/10323159/specifying-decimal-places-on-a-variable-in-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!