John Doe
John Doe

Reputation: 183

Difference in math between VB.Net and PHP

I am porting my own VB.Net utility to PHP, which is used to extract meta-data info out of photos (EXIF) along with GPS Coords. The problem is that i get different results in PHP. I know the correct output is VB.Net's because i tested it with a photo taken in my home.

The math operations i use are

VB.Net

degrees + (minutes / 60) + (seconds / 3600)

PHP

$longDegreesResult + ($longMinutesResult / 60) + ($longSecondsResult / 3600)

But the results are not the same! Is there any difference in PHP calculations, or any "rounding" of the numbers that i should know about?

Thanks!

Upvotes: 0

Views: 172

Answers (2)

John Doe
John Doe

Reputation: 183

I realised that PHP won't give me enough numbers AFTER comma. VB.Net shows from 1 to 2 more of them. Wtf... guys thank you all! I will try to find the reason PHP "cuts" the output. Thanks again!

EDIT: The answer was ini_set('precision', 20);

Thank you all!

Upvotes: 0

invisal
invisal

Reputation: 11181

This is the VB.NET code

Sub Main()
    Dim degrees As Double = 23 / 1
    Dim minutes As Double = 45
    Dim seconds As Double = 1031 / 100

    Console.WriteLine(degrees + (minutes / 60) + (seconds / 3600))
End Sub

And this is PHP code

$degrees = 23 / 1;
$minutes = 45;
$seconds = 1031 / 100;

$result = $degrees + ($minutes / 60) + ($seconds / 3600);

echo $result;

They print the same result:

23.752863888889

Upvotes: 1

Related Questions