MySQL - Floats rounding up/down -
Saize - 04.02.2015
Hey guys
Iґve got a small problem with MySQL, I can read and set floats in the DB, but it always is rounding up/down itself.
I couldnt find a fix yet, does someone know how to fix it?
PHP код:
public OnPlayerDisconnect(playerid, reason)
{
new Query[256];
GetPlayerPos(playerid, pInfo[playerid][posX], pInfo[playerid][posY], pInfo[playerid][posZ]);
mysql_format(mysql, Query, sizeof(Query), "UPDATE accounts SET Score='%d', VIP='%d', Money='%d', PosX='%f', PosY='%f', PosZ='%f' WHERE ID='%d'",
pInfo[playerid][Score], pInfo[playerid][VIP], GetPlayerMoney(playerid), pInfo[playerid][posX], pInfo[playerid][posY], pInfo[playerid][posZ], pInfo[playerid][ID]);
printf("%s", Query);
mysql_tquery(mysql, Query, "", "");
return 1;
}
PHP код:
pInfo[playerid][posX] = cache_get_field_content_float(0, "PosX");
pInfo[playerid][posY] = cache_get_field_content_float(0, "PosY");
pInfo[playerid][posZ] = cache_get_field_content_float(0, "PosZ");
pInfo[playerid][FacingAng] = cache_get_field_content_float(0, "FacingAngel");
AW: MySQL - Floats rounding up/down -
Saize - 04.02.2015
Iґve already tried it but it keeps rounding up/down the floats
AW: MySQL - Floats rounding up/down -
Saize - 04.02.2015
That didnt really help
Re: MySQL - Floats rounding up/down -
Vince - 04.02.2015
Floating point values aren't exact because that is their nature. If you really care that much about that 0.001 offset, add '+ 0' to your column in the select query. It's not like you are anyone else is going to notice that they spawn 1 centimeter to the right of where they're supposed to spawn.
AW: Re: MySQL - Floats rounding up/down -
Saize - 04.02.2015
Quote:
Originally Posted by Vince
Floating point values aren't exact because that is their nature. If you really care that much about that 0.001 offset, add '+ 0' to your column in the select query. It's not like you are anyone else is going to notice that they spawn 1 centimeter to the right of where they're supposed to spawn.
|
its not a centimeter its more like when the float is set +0.0003 the spawn position changes for around 8 meters or smthn (kinda weird but its like that, if you believe me or not)
and its not always the same difference its more like its randomly rounding the floats
Re: MySQL - Floats rounding up/down -
PowerPC603 - 04.02.2015
Is your enum setup to hold PosX, PosY, PosZ to hold floats?
Also, is your table setup to have these fields store floats as well?
Otherwise I wouldn't know what could be causing this.
A difference of 8 meters or so isn't rounding up/down, it's more like converting from one variabletype to another.
AW: Re: MySQL - Floats rounding up/down -
Saize - 04.02.2015
Quote:
Originally Posted by PowerPC603
Is your enum setup to hold PosX, PosY, PosZ to hold floats?
Also, is your table setup to have these fields store floats as well?
Otherwise I wouldn't know what could be causing this.
A difference of 8 meters or so isn't rounding up/down, it's more like converting from one variabletype to another.
|
The 8 Meters was just used as an example but its some meters away from the spawn where I log out and yes its set to flaot in the DB
AW: MySQL - Floats rounding up/down -
Saize - 05.02.2015
Bump
Re: MySQL - Floats rounding up/down -
Maximus0 - 05.02.2015
Hello Saize,
You have described your problem properly and title will set an exact value to preview if someone searches on ******/bing/etc.
Steps to get your problem fixed- On MySql table, for PosX, PosY, PosZ put type as Decimal
- It should be PosX='%.2f' instead of PosX='%f'
I didn't try it, but pretty sure will work fine as my mind saying.
AW: MySQL - Floats rounding up/down -
Saize - 06.02.2015
Iґve already tried it that way
Iґve heard something about mysql_fetch that could fix it, so I checked the wiki but it didnt really help, someone knows another way to fix this?