Converting float to 1 decimal point - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Converting float to 1 decimal point (
/showthread.php?tid=570588)
Converting float to 1 decimal point -
MP2 - 11.04.2015
EDIT: Nevermind, I figured it out.
AW: Converting float to 1 decimal point -
Mencent - 11.04.2015
Hello!
You have to usw format:
PHP код:
new floats = 1.422134,string[20];
format(string,sizeof string,"%0.1f",floats);
print(string);
Mencent
Re: Converting float to 1 decimal point -
MP2 - 11.04.2015
You don't
have to use format, and I'd rather not as it's slow. I also don't want it as a string, and I would have to then convert it back to a float.
EDIT: Managed to figure it out. Was simple.
AW: Re: Converting float to 1 decimal point -
Nero_3D - 11.04.2015
Quote:
Originally Posted by MP2
EDIT: Managed to figure it out. Was simple.
|
Willing to share?, just interested
Re: Converting float to 1 decimal point -
MP2 - 12.04.2015
pawn Код:
stock Float:ConvertFloatToOneDP(Float:value)
{
new Float:result;
new tempInt;
result = value * 10.0;
tempInt = floatround(result);
result = float(tempInt);
result = result / 10.0;
result = result + 0.0000006; // Fixes floating point inaccuracy (e.g. 0.99999999)
return result;
}
Perhaps there is a better method, but for me it was this or format.