Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

numbers driving me mad 1

Status
Not open for further replies.

andyc209

IS-IT--Management
Dec 7, 2004
98
GB
I have 3 values from a query

value1 = 1000.50
value2 = 200
value3 = 50

if I add them together instead of getting 1250 i keep getting 100020050.I assume this is to do with numeric / string stuff. how can i get them to add to 1250 whilst retaining 2 decimal places as sometimes value1 may be 1000.40.
 
There are a couple ways, but they all involve converting your value to a number.

You could do this...

cSng(Value1) + cSng(Value2) + cSng(Value3)

This will convert your string values to the single data type prior to doing the addition. Alternatively...

Val(Value1) + Val(Value2) + Val(Value3)

Either way, you need to convert to a number first.


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
thanks for this, seems to work, cheers.
 
you can try cdouble(val) or cint(val) I am not so sure, but it is might work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top