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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(3.0 + 5.7 +0 )* 100 = 869 ?????

Status
Not open for further replies.

jackiev

MIS
Aug 16, 2000
56
US
Have a VB6 program that sums the values
in the columns of an Access table. The
values are double fixed numbers, the final
sum needs to be converted to a string, ignoring
the decimal point, so 37.95 becomes 3795
and 14.00 becomes 1400.

Table contains:
Week# Mon Tue Wed Thu Fri
1 3.00 5.70 0.00 0.00 0.00


code is:
dblSum = Mon.value + Tue.value + Wed.value +Thu.value + Fri.value
dblSum = dblSum * 100
strSum = cstr(Int(dblSum)) **

** after this step, dblSum = 870 amd strSum = 869
CAN ANYONE SHED SOME LIGHT ON THIS???
 
dblsum is probably internally represented as 869.99999999
and when you take the Int(which does not round) function you get 869. Double precision numbers often have this type of internal representation. The roundoff may be coming form any of the individual values. I would guess that Tue.Value is 5.699999999

strSum = cstr(Int(dblSum + 0.5)) should take care of the problem. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Well, If I had just searched a little further, I would have found my answer on this forum.
Looks like 'sparrow' had the same question in Jan 2001, & the answer is there in the replies to that posting.
Sorry for wasting anyone's time.
It is just an indicator of the HUGE value of these forums...
Answering questions before they even get asked ..
Thanks anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top