# Is there a difference in Log10 in VB.net 2008 and Excel?

### Question

• Hi

I get different results when i do this calculation in excel and vb.net

Value 1 and 2 is a double with 1 significant decimals.

and i do this 10* math.Log10( 10^(0.1*value1- 0.1*value2))

and i get different results in excel and vb.net....

My question...

is there a difference in Log10 algorithems in Excel and VB.net and/or is the values used in Excel not a double (Singel  or decimal perhaps)?

And I know.... I could post this on a VBA forum...

Kenneth
Tuesday, June 30, 2009 12:02 PM

• Hi Kenneth Haugland,

I think you can check the programming logic in your porjcet. Maybe there are some oversights.
"They will use the maximum number of decimals in calculations in both?"
Because the result of your calculation is infinite. So they will show the maximum precision of themselves. You will notice that vb will be more precise than excel.

Best Regards

Yichun Feng

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Thursday, July 02, 2009 10:58 AM

### All replies

• Is this a repeat of this one?

www.insteptech.com
Tuesday, June 30, 2009 5:13 PM
• No.... I got different numbers in excel and vb with calculating the same values... error vas in the region of 0.02 dB so not a problem... but still.... I'd like to know...

Lot of numerquestions today...... :s
Kenneth
Tuesday, June 30, 2009 5:19 PM
• Hi Kenneth Haugland,

Please try to calculate this in VS and Excel: ( 10^(0.1*value1- 0.1*value2)). Do you have different results?
I think this is not cause by log10. I've tested log10(1.5) in VS and Excel. The result is just same except the precision.

Best Regards

Yichun Feng

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Thursday, July 02, 2009 9:53 AM
• the problem is that I have a measured sound pressure level outside and inside .....

The level inside in dB is corrected with background noise....

So in correcting for Noise gives me this equation:

10 * MAth.log10(10^(Lp/10) - 10^(Lnoise/10)

Here the results are marginally higher in the higher frequenses.... And I get a difference of about 0.01 - 0.02 from excel to vb.net ... (The input level has one segnificant number after decimal)

The hole program is rader large in both excel and vb.net... or else I would hae given you the code and xls to compare :)

Kenneth
Thursday, July 02, 2009 10:11 AM
• Hi Yichun Feng

I did this test in vb.net

Dim d1, d2, d3 As Double

d1 =

CDbl(TextBox1.Text.ToString())

d2 =

CDbl(TextBox2.Text.ToString())

d3 = 10 * Math.Log10(10 ^ (d1 / 10) - 10 ^ (d2 / 10))

TextBox3.Text = d3.ToString

andf this in excel

=10*LOG10(((10^(A1/10))-((10^(B1/10)))))

I get the same results in both... Must be a bug in my programming then i assume.... They will use the maximum number of decimals in calculations in both?

Kenneth
Thursday, July 02, 2009 10:33 AM
• Hi Kenneth Haugland,

What version of excel and VS are you using?
You said that you got a difference of about 0.01 - 0.02 from excel to vb.net . However, it is all the same on my computer.

I use this in VS2008:
Dim Lp As Double = 0.02
Dim Lnoise As Double = 0.01
MsgBox(10 * Math.Log10(Math.Pow(10, (Lp / 10)) - Math.Pow(10, (Lnoise / 10))))

result = -26.3628421535947

This in excel 2007:
=10*LOG10(10^(0.02/10)-10^(0.01/10))
result =  -26.36284215

Best Regards

Yichun Feng

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Thursday, July 02, 2009 10:35 AM
• Hi Kenneth Haugland,

What version of excel and VS are you using?
You said that you got a difference of about 0.01 - 0.02 from excel to vb.net . However, it is all the same on my computer.

I use this in VS2008:
Dim Lp As Double = 0.02
Dim Lnoise As Double = 0.01
MsgBox(10 * Math.Log10(Math.Pow(10, (Lp / 10)) - Math.Pow(10, (Lnoise / 10))))

result = -26.3628421535947

This in excel 2007:
=10*LOG10(10^(0.02/10)-10^(0.01/10))
result =  -26.36284215

Best Regards

Yichun Feng

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

Using Excel 2007 and VB Express 2008 with Sp1 3.5

My result with you input numbers
Vb : -26,3628421535947

Excel:  -26,3628421535947000

Kenneth
Thursday, July 02, 2009 10:38 AM
• Hi Kenneth Haugland,

I think you can check the programming logic in your porjcet. Maybe there are some oversights.
"They will use the maximum number of decimals in calculations in both?"
Because the result of your calculation is infinite. So they will show the maximum precision of themselves. You will notice that vb will be more precise than excel.

Best Regards

Yichun Feng

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Thursday, July 02, 2009 10:58 AM