Floats confusion
#1

So I changed a calculator command I had, which only worked with integers, to work with float numbers.
It all "worked" fine except, for example, I type:

/calculate 1.4 1.4 add
it sends the messages:
1.39999 + 1.39999 = 2.79999

Why does it change the 1.4 to 1.3999?

Cheers,
haven't worked with floats too much.
Reply
#2

Can you show the code for the calculator command?
Reply
#3

pawn Код:
CMD:calculate(playerid, params[])
{
    new Float:Value1, Method[20], Float:Value2, string[128];
    if(sscanf(params, "ffs", Value1, Value2, Method))
    {
        SendClientMessage(playerid, GREY, "SYNTAX: /calc(ulate) [value] [value] [method]");
        SendClientMessage(playerid, GREY, "Method: Add, Subtract, Multiply & Divide.");
    }
    else
    {
        if(strcmp(Method, "add", true) == 0)
        {
            new Float:Sum = Value1 + Value2;
            format(string, sizeof(string), "%f + %f = %f.", Value1, Value2, Sum);
            SendClientMessage(playerid, WHITE, string);
        }
    }
    return 1;
}
Reply
#4

Try this:
pawn Код:
format(string, sizeof(string), "%0.2f + %0.2f = %0.2f.", Value1, Value2, Sum);
Reply
#5

Didn't fix it.
Now it says:
1.39 + 1.39 = 2.79.
Reply
#6

I don't know will this help but try: https://sampwiki.blast.hk/wiki/Floatadd
Reply
#7

It's a limitation in the system - it does it with floats a lot, there's a thread around here explainin it somewhere... (i know from workin with floats)
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)