Converting float to 1 decimal point
#1

EDIT: Nevermind, I figured it out.
Reply
#2

Hello!

You have to usw format:
PHP код:
new floats 1.422134,string[20];
format(string,sizeof string,"%0.1f",floats);
print(string); 
Mencent
Reply
#3

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.
Reply
#4

Quote:
Originally Posted by MP2
Посмотреть сообщение
EDIT: Managed to figure it out. Was simple.
Willing to share?, just interested
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)