Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

How can I prevent data trancation?

  Asked By: Bertha    Date: Dec 09    Category: Asp.net    Views: 5260
  

I need some assistance in ASP. I am trying to display prices from an
Access database using ASP, but the prices are being trancated. ie
$10.50 is being display as $10.5 How can I prevent this from occuring?
The price field in the database is of currency type with 2 decimal
places.

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Lee Butler     Answered On: Dec 09

I've used Access recently and didn't state decimal places - currency  and set it to Auto.

[Else count dps after point and add a zero - assuming $10.51 is displayed as $10.51 ok)

 
Answer #2    Answered By: Jennifer Davis     Answered On: Dec 09

I tried putting Auto but it does not do the trick. I
cannot count the number of characters and then put a
zero coz some prices  are like $10.00 and they get
displayed as $10 instead.
What if I converted the price variable to a string in
ASP and then display  it? Anyone got any idea how to do
that?

 
Answer #3    Answered By: Beaudi Smith     Answered On: Dec 09


double d = 12345.6789;
string s = d.ToString("C");

s now equals "$12,345.68"

MSDN info on Formatting Numerics.
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconstandardnumericformatstrings.asp

 
Answer #4    Answered By: Sophia Campbell     Answered On: Dec 09

I have had problems similar in the past.

Tas ... check that the values haven't actually been altered in the actual database. That can happen - if you set it wrong the first time it alters all your values in the database, turning 10.50 into 10.5, etc, so when you do get it right you still have the same problem.

Turning things to strings to display  them sounds like a good idea, I take it we are talking asp.NET and not asp  ..... then you can do what you want with them.


Try

<%# DataBinder.Eval(Container.DataItem, "price", "£{0:N2}")%>

in your aspx/ascx page for the formatting.

 
Answer #5    Answered By: Andrew Brown     Answered On: Dec 09

The data  in the database  is ok. So the problem is not
that. I am using asp  and not ASP.NET. Do u know the
syntax with ASP?

 
Answer #6    Answered By: Gustavo Costa     Answered On: Dec 09


<%@ Language=VBScript %>

<%
Response.expires = 0

Set conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Set comm = Server.CreateObject("ADODB.Command")
'conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" &
Server.MapPath(dbPath)
'conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & dbPath
'conn.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath

conn.open"driver={Microsoft Access Driver
(*.mdb)};dbq=F:\dabs\grid\cs\dabs.mdb"

rs.open "stock", conn, 2, 2


if not rs.eof then rs.movefirst
do until rs.eof
%>

<div align="center">
<table border="1" width="600">
<tr>
<td width="200"><%= FormatCurrency(rs("Ex Vat")) %></td>
</tr>
</table>
</div>


<%
rs.movenext
loop
%>

<% rs.close() %>


formats it to dollars - dunno about any other currencies ????
as found at
mk:@MSITStore:c:\MSDN98\98VSa\1033\vbscript.chm::/htm/vsfctFormatCurrency.ht
m

 
Didn't find what you were looking for? Find more on How can I prevent data trancation? Or get search suggestion and latest updates.




Tagged: