MySQL r39-2 inserting precise floats -
The_Scope - 10.01.2015
Hello, i need to save some objects cordinates into a database but when i save them, the numbers get change in the database.. i searched and i found that FLOAT, DOUBLE and other mysql row types aren't precise, so that's why my cordinates get changed.
The question is how could i save my cordinates exactly as they are in-game? I tried with DECIMAL, int, varchar, text, i don't know what should i use..
pawn Код:
mysql_format(MySQL, query, sizeof(query), "INSERT INTO gates (Model, Password, Owner, closePosX, closePosY, closePosZ, closePosRX, closePosRY, closePosRZ, openPosX, openPosY, openPosZ, openPosRX, openPosRY, openPosRZ) VALUES ('%i', '%s', '%s', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f')",
Gate[NextID][Model],
Gate[NextID][Password],
Gate[NextID][Owner],
Gate[NextID][closePosX], Gate[NextID][closePosY], Gate[NextID][closePosZ], Gate[NextID][closePosRX], Gate[NextID][closePosRY], Gate[NextID][closePosRZ],
Gate[NextID][openPosX], Gate[NextID][openPosY], Gate[NextID][openPosZ], Gate[NextID][openPosRX], Gate[NextID][openPosRY], Gate[NextID][openPosRZ]);
mysql_tquery(MySQL, query, "OnGateCreate", "i", NextID);
I think i should use DECIMAL, but: should i make a system to get amount of characters of the hole float and amount of characters behind the coma and insert it into the database with "DECIMAL(characters,characters behind coma) ? I really don't know if there is an easier way..
Thanks for reading, scope.
Respuesta: Re: MySQL r39-2 inserting precise floats -
The_Scope - 10.01.2015
Quote:
Originally Posted by ******
The floats you are saving are not precise in the first place - no floats are. If you really care, see IEEE-754 for more information.
|
The problem is that that floats in-game works, because the objects get created in that positions. But when i insert it into the database they get change, so when i load the objects from the database no objects are created in-game. I'll search IEEE-754.
Example:
In-game cordinates:
X, Y, Z, RX, RY, RZ, (when i create the objects from the server)
-77.943626, 1.293159, 3.117187, -1.000000, -1.000000, -1.000000
In table with DECIMAL(10,6):
-77.944000, 1.293000, 3.117000, -1.000000, -1.000000, -1.000000
You see, they are pretty similar, but with that small change objects aren't created..
Respuesta: Re: MySQL r39-2 inserting precise floats -
The_Scope - 10.01.2015
Quote:
Originally Posted by ******
The floats you are saving are not precise in the first place - no floats are. If you really care, see IEEE-754 for more information.
|
I read about IEEE-754 and i found a converter:
http://www.h-schmidt.net/FloatConverter/IEEE754.html I tried and worked successfully.
The question is: How could i make the calculation in pawn? I couldn't understand perfectly how it works
EDIT: I tried to convert -77.944000 again with the converter and didn't work, i thought it was working but no
Re: MySQL r39-2 inserting precise floats -
Vince - 10.01.2015
I'm not sure where you're going with this. Who cares about that 0.0001 offset that no one will see?
Respuesta: Re: MySQL r39-2 inserting precise floats -
The_Scope - 10.01.2015
Quote:
Originally Posted by Vince
I'm not sure where you're going with this. Who cares about that 0.0001 offset that no one will see?
|
Quote:
Originally Posted by ******
Indeed, in real terms, those co-ordinates are off by less than half a millimetre. Of course GTA units don't map perfectly 1:1 with metres, but it is a useful estimate.
|
So maybe the problem is in my loading function, but i think it's okay..
EDIT: Thanks guys, the problem was i wasn't loading the Model of the object, so the objects where created with id 0.