format/printf precision bug -
Kar - 11.08.2016
Not sure if reported before:
pawn Код:
CMD:changefloat
(playerid, params
[]){ new Float:fTest
= 97.10, szStr
[64];
printf("printf:: fTest is %.2f.", fTest
);
// result: "printf:: fTest is 97.09." format(szStr,
64,
"fTest is %0.2f.", frequency
);
SendClientMessage
(playerid,
-1, szStr
);
// result: "fTest is 97.09." mysql_format
(mysqlConnHandle, szStr,
64,
"fTest is %0.2f.", frequency
);
// workaround at https://github.com/pBlueG/SA-MP-MySQL/blob/6c7a8cfc36068e9dcda6fcc017c3a0e6738cc9c6/src/CScripting.cpp#L963 for whoever uses this plugin SendClientMessage
(playerid,
-1, szStr
);
// result: "printf:: fTest is 97.10." return 1;
}
Seeing that NEARLY everyone is misunderstanding the code for what reason I DON'T understand.
Here:
First set a test float variable Float:fTest to 97.10;
Use printf/format and print the variable.. it will print 97.09.
I found a workaround for anyone who wants this fixed, and they use the MySQL plugin.. they may use mysql_format to make it print 97.10 successfully.
Re: format/printf precision bug -
Luicy. - 11.08.2016
Misleading title, this is a mysql_* bug
Edit; chabge IT to %f
Re: format/printf precision bug -
Spmn - 11.08.2016
Quote:
Originally Posted by Luicy.
Misleading title, this is a mysql_* bug
Edit; chabge IT to %f
|
Stop, please!
It's not really a bug. It happens due to the way float numbers are represented in memory. Take a look here:
http://stackoverflow.com/questions/1...g-point-number
Re: format/printf precision bug - WhiteGhost - 11.08.2016
Quote:
Originally Posted by Luicy.
Misleading title, this is a mysql_* bug
Edit; chabge IT to %f
|
No Spam - If you are adding no useful information to a topic, you are spamming. This includes memes of any sort, especially in the more serious areas of the forum.
No Useless Replies - If you are unsure or don't know how to proceed with solving an issue, then do not respond to the thread, it will be considered spam.
1. English..
2. Dont you think he knows its a mysqlf,Retard?
Anyways,Yes it's been reported before...
Re: format/printf precision bug -
Kar - 11.08.2016
Quote:
Originally Posted by Spmn
|
That issue is only for "12.1"?
And how does it work fine in mysql_format? It can be fixed.. I'm sure format is a custom made function just like mysql_format!
This has NOTHING to do with mysql, wtf? mysql_format is the workaround, I was just showing how I fixed it if anyone wants.
Re: format/printf precision bug -
Crayder - 11.08.2016
So you're talking about the MySQL plugin bug?
EDIT: Oops, late, had this tab open for a while.
And no, "format" is not a "custom made" function. It's a PAWN native. Go look at the PAWN compiler's code so you can see how it's precision is done.
EDIT: Found it for you:
https://github.com/compuphase/pawn/b...xstring.c#L960
Re: format/printf precision bug -
Vince - 11.08.2016
Floating point values can't be stored with exact precision. That is their nature. Read page 3 and 4.
http://www.compuphase.com/pawn/Float...nt_Support.pdf
Re: format/printf precision bug -
Kar - 12.08.2016
Urgh, does noone see what I'm trying to do here?
IMO: The fact that Kalcor removed the strformat from string.inc and added a format in a_samp shows to me that format is indeed a custom made (or atleast altered for sa-mp) function by the SA-MP devs. E.G "- Adds %q to format(). %q is the same as %s although the input will first be passed through sqlite's string escaping function.".
mysql_format is a custom made function, it's fixed in that but not fixed in format. It's just another minor bug that Kalcor would put alot of things over it in development. I just used mysql_format to show the correct behaviour.
Re: format/printf precision bug -
Spmn - 12.08.2016
I remember reading somewhere that format() function is based on AMX Mod X format(), so take a look here:
https://github.com/alliedmodders/amx...ormat.cpp#L549
Even if format() would be the same function from string.inc, this doesn't mean that it can't be modified as long as developers have access to amx vm source code.