Mysql fetching problem
#1

Hello guys, i've got a little problem here:

I have some data stored in my database with a column containing a float, which should be the quantity of the item (0.1 min).
The problem is: when i try to subtract, let's say 0.1 from 10.0 from that float in-game, and transfer it into a new container, if i fetch the mysql data from SAMP, the game will tell me i have 9.8 and 0.1, which is 9.9 together.

The weirdest thing:
If i access my mysql database and look in it, the floats will clearly show as 9.9 and 0.1, which is 10.0 the right value that should come out in-game.

The whole system is working, inserting data, updating it, creating and deleting rows, this issue comes out only when i subtract 0.1 from 10.0 (example) but not when i subtract 0.2 from 10.0.

quant = The float in the database
quantity = The float i define to transfer
oQuantity = quant - quantity

Saving
Код:
		new Float:oQuantity = (quant - quantity);
		if(quantity == quant) {
			mysql_format(handlesql, query, sizeof(query), "DELETE FROM drugs WHERE ID = %d LIMIT 1", did);
			mysql_query(handlesql, query);	
		}
		else {
			mysql_format(handlesql, query, sizeof(query), "UPDATE drugs SET Quantity = %.1f WHERE ID = %d", oQuantity, did);
			mysql_query(handlesql, query);	
		}
Showing
Код:
			case 1..3: {
				format(drugmessage, sizeof(drugmessage), "{EEA823}[{FFFFFF}%d{EEA823}]{FFFFFF} Small Bag | %s | %0.1f/28.0%s",
					zipquant, drug, DrugInfo[drugid][dQuantity],dose);								
				SCM(playerid,COLOR_WHITE,drugmessage);	
			}
This is what comes out when i print the value of "quantity" in both %f and %.1f
Transfer drug > QUANTITY: 0.100000 DOTONEF: 0.1
Reply
#2

quant = The float in the database
are u sure it's correct? I mean if it is cached from the database.

also, make output and post it for a better vision.
printf("UPDATE drugs SET Quantity = %.1f WHERE ID = %d", oQuantity, did);
Reply
#3

Transferring 0.1 from 10.0 The output gives:
UPDATE drugs SET Quantity = 9.8 WHERE ID = 50
...Weird:
  • The quant is retrieved from a PVarFloat that gets defined when you first send the cmd (transferdrug [id])
quant = cache_get_field_content_float(Row, "Quantity"); <- retrieves the quantity float from ID 50
SetPVarFloat(playerid,"quantFloat",quant); <- sets the float for the transferring action
  • And the quantity you insert in the dialog:
SetPVarFloat(playerid,"DrugquantFloat",floatstr(in puttext)); (It's actually showing as in puttext with a space here but it doesn't have a space i don't know why lol)


Test i've made right now:
Giving myself 10.0, transferring 0.1 into a new container, the container with 0.1 creates and the new quantity shows as 9.8, but in the database it's clearly 9.9





Database:



Edit:

New test:
After this test i've made, and it was showing 9.8, i transferred 0.1 two times again.
1st time [02:57:50] UPDATE drugs SET Quantity = 9.7 WHERE ID = 50 (<- was still showing 9.8 when listing)

2nd time [02:58:13] UPDATE drugs SET Quantity = 9.6 WHERE ID = 50 (<- was listing 9.6 when listing but in the database it's 9.7)

Update:
Tested with a quantity of 0.2 on a quantity of 10.0
[03:47:55] UPDATE drugs SET Quantity = 9.8 WHERE ID = 56 ( Database showing 9.8 )

Tested with a quantity of 0.3 on a quantity of 10.0
[03:50:18] UPDATE drugs SET Quantity = 9.6 WHERE ID = 58 ( Database showing 9.7 )

So the issue is coming from "odd" numbers? (0.1 - 0.3 - 0.5) ecc
Reply
#4

Anything already known about this type of issue? I can't really figure out what the problem is... Also can't find nothing regarding similiar problems on the web.
Reply
#5

Use this? https://sampwiki.blast.hk/wiki/Floatsub
Reply
#6

Quote:
Originally Posted by Logic_
Посмотреть сообщение
Sadly also this is not working, tried right now.. also
SAMP WIKI: Note that this function has no real use, as one can simply use the standard operator (-) instead.
And the database is saving correctly. It’s just sa:mp showing a wrong value everytime.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)