473,382 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Adding decimals from a database

147 100+
Hi

I have a simple code which needs to add 2 decimals together but alas, it won't. The figures are stored on an SQL database (as a decimal). The site uses asp (vb script)
Lets pretend MaleHeight = 1.2 and FemaleHeight = 2.5
Expand|Select|Wrap|Line Numbers
  1.  <%
  2. dim h1, h2, total
  3. h1 = rsPCB.Fields.Item("MaleHeight").Value 
  4. h2 = rsPCB.Fields.Item("FemaleHeight").Value   
  5. total = h1 + h2
  6. Response.Write(total)
  7. %>
Line 5 (total = h1 + h2) gives me the error Type mismatch.

If I add cInt to h1 and h2, it does the maths but doesn't show the decimal place. The result is 3 instead of 3.7

However, if I add Response.Write("h1= "& h1 &"") before line 5, the result is 1.2! I can't see why total can't add/display the result.

Any ideas?
Aug 4 '09 #1
4 3858
jhardman
3,406 Expert 2GB
I assume that since you found the csng function on w3schools, you got your thingy working. the reason cint didn't work is that it converts the argument into an integer (cint stands for Convert INTeger). Anyway, glad you got it working.

Jared
Aug 5 '09 #3
DaveRook
147 100+
Hi Jhardman.

Thanks, yes all working. I find it strange in VBscript you don't need to declare the variable type which is why I couldn't work out what to do. Unless there is a way to do dim variable as string etc

Thanks

Dave
Aug 6 '09 #4
jhardman
3,406 Expert 2GB
@DaveRook
You are definitely right, that is one of the biggest drawbacks of VBScript. And since I was working with VBScript before I was a serious professional, it is something I still think about backwards sometimes. Anyway, glad you got it up.

Jared
Aug 7 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: rob | last post by:
Hi all, Very simple question, is it possible to add the contents of session variables? for example I have 2 session variables, product1 & product2 , if I try and add them I get a "type...
2
by: Brian Daoust | last post by:
Hello everyone, I have an Access database with a table that has a text field. The data in the text field looks like: 3456.45.4343 Not sure why this is a text field, but it is. Anyways,...
3
by: munkis29 | last post by:
Hey all, Hopefully someone here can help me, I've got a problem and not sure how to aproach it. I'm using Access 2003 and have a table with one field: FileID in it there are many values, many of...
1
by: roger2282 | last post by:
help, I am trying to update a field on my database and cant seem to get the right value stored eg on reading the database field i get the values I need such as 31.24, 3.15 and 16.00 and I...
3
by: Jx4 | last post by:
Hi there, I am currently having trouble with some issues with adding Currency values. I have one column with values of transactions and the other column has a running total. It works great...
1
by: Capn Stoobie | last post by:
I have a database that I regularly import data into from a text file. The text file is produced by payroll software, and it is always the same format. Most of the time my acImportDelim command...
3
by: Mario Pais | last post by:
I have a problem with the decimals in a report I created in Access Database. In a table I have two fields. One is the "price" the second one is "quantity". When I develop a report I would like to...
135
by: robinsiebler | last post by:
I've never had any call to use floating point numbers and now that I want to, I can't! *** Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) on win32. *** 0.29999999999999999 0.29999999999999999
3
by: Celal | last post by:
Hi, I couldn't get around a problem about decimal rounding up when adding a record to a table from a form by programming a button. I have an invoice form where the grand total is a calculated text...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.