Java Logarithm and answer using calculator not equal

Viewed 25

I am new to Java, sorry I have this wield question came up, I tried to do log(0.5) in Java using Math.log(0.5), I did log(0.5) in calculator and answer is -0.3 and I computed Math.log(0.5), answer is -0.69. Any one know where I did it wrong?

1 Answers

Math.log calculates a "natural logarithm", that is, base e. On your calculator, this might be denoted by a button ln or similar.

To get a "common logarithm", that is, base 10, you need Math.log10. This is the function represented by the log button on your calculator.

Related