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

Excel calculations in VB 1

Status
Not open for further replies.

jgarry

Programmer
Nov 23, 2004
67
US
Hi, thanks in advance,

I am moving some calculations from Excel to Vb, I am having a tough time with one of the calculations.

4.1886226531/360 this is the Excel Calculation(shortened)
the answer in Excel is .011635062925495


in VB I am writing it to be
dbl_temp1 = 4.1886191152

dbl_temp2 = (dbl_temp1 / 360)

the answer in vb is 1.16350530977778E-02


I only need to carry out the decimal 5 positions. The aswer are about the same except vb has the E stuff going on. I am not a math major and I am not sure how to eliminate the E in the answer.

Thanks again

Jim
 
Hey, thanks again

I got some inside help from our expert at the office. this is how it was fixed

format(dbl_temp2,"000.00000") now both calcs come out the same .

Thank you again for your assistance.

Jim
 
Personally, I would use the round function, so:
Code:
dbl_temp2 = round(dbl_temp2, 5) rather than the format function.  Lots of messy behind the scenes conversions are happening with the format function.

What you're actually doing is this:

1.   Converting the double to a string.
2.   Formatting the string to show 5 decimal places.
3.   Converting the formatted string back to a double.

With the round function, you're just rounding the double to 5 decimal places.  Looks cleaner, too, and you never have to worry about how many places there are to the left of the decimal.  

Now, just so you know, 1.16350530977778E-02 means "1.16350530977778 times 10 to the -2", or .0116350530977778.  "Scientific notation" works quite well with big numbers, especially with lots of zeros in them, and that's what it's intended for.  So, you express the number with one digit to the left of the decimal point, and count the number of places that you have displaced the decimal point.  I'll give a couple more examples and see if that makes it clear.

13484000 = 1.3484E+07
.0000011635 = 1.1635E-06

HTH

Bob
 
Thank you for your response, I am changing from the format to the round function.

Thank you for your help

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top