Suport MYSQL float error
#1

My friend asked me to do this topic now, 'cause he kind of gave up, he was trying I Fize is another way to see if I could, but nothing I exchange is only generated errors or did not work, I just like doing his

We do not know why, but when we create a home is taken the position of the player and played for OutX positions, taking the X player and so for Y and Z and qnd it goes to the database is a somewhat position different than the position that was supposed to be for example

We create a home:
That was the position X, Y, Z in / save
X: 2495.3486
Y: -1690.9208
Z: 14.7656

And that was the OUT X, Y, Z that was saved in the database
X: 2495.35
Y: -1690.92
Z: 14,766

It's all being rounded and out the right position seems we do not know why, and he knows more about the logic and I can not solve, no longer know what to do, he says that the problem is related to MySQL as he had done in DINI and worked absolutely right and when you create the house everything works right, absolutely right, when you restart the server the whole house is outside the right position


----------------------------------------------------------------------------------------------------------------------------------

I tried to change the database, FLOAT to DECIMAL or DOUBLE, DOUBLE but was so
Pos which was to be
2523.1970
-1679.2944
15.4970

Pos who saved
2523.197
-1679.294
15,497

It seems that instead of cutting 2, 1 cut this time
FLOAT, failed, or DOUBLE, DECIMAL I do with?

The decimal saved like this:
2495
-1691
15

That's right, no commas, no longer know what to do, was it not the decimal size 10.0? Someone help me!

Sorry my english
Reply
#2

The rounding occurs by floats in ALL programming languages, not just SAMP and/or MySQL.
It's because the computer uses 32-bits to store the value and you can't get unlimited precision because of this.
64-bit floats are more accurate and MySQL supports them, but SAMP doesn't.

And why do you care that they are rounded to 0.001 precision?

That's 1 millimeter in most games, as most games use distances of 1.0 equal to 1 metre.

Even 0.00000000 stored in a float will become something like 0.0000001 or so, because of the limit of 32-bits.

That's also the reason why you can't compare floats exactly.
You always have to specify a range like -0.001 < value < 0.001.
If value is between those values, you can assume it's very close to 0, but you'll never succeed in checking if a float equals 0.000000000000000000000000000000000...


Also, the higher the number before the dot, the less precision you have behind the dot.
For single digit values, you could have up to 6 digits behind the comma in a float.
Like 7.481354.

But very high numbers like 48915 in a float would become only 48915.23 or something like that.
In every programming language the result may be a bit different, but you're still limited to a 32-bit integer memory-location holding all the info to represent a float.

Inaccuracies occur always, you can't get around it.
Unless you split up the value before and after the dot by 2 integer values, which you store separately and merge them back together in a string.

Even then, you're limited in digits either way.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)