FloatRound not work!
#1

Код HTML:
E@_R[GetPlayerVehicleID(playerid)] = floatround(Veh[r][KM], floatround_round);
printf("FLOATR: %s", floatround(Veh[r][KM], floatround_round));// DEBUG
DEBUG .LOG:
Код HTML:
FLOATR: 2.312
-----------------
Veh[r][KM] is 0.751, not 2.312.
Reply
#2

You are trying to print a string, use %d for integers.

printf("FLOATR: %d", floatround(Veh[r][KM], floatround_round));
Reply
#3

Quote:
Originally Posted by OllieSimons
Посмотреть сообщение
You are trying to print a string, use %d for integers.

printf("FLOATR: %d", floatround(Veh[r][KM], floatround_round));
Or %i.
Reply
#4

The point of floatrounds at your case to turn the values that you have as a float into an integer, so as the mates said earlier, use %d or %i (both for integers) instead of %s (which is for string).
Reply
#5

OK.
Код HTML:
E@_R[Veh[r][ServerID]] = floatround(Veh[r][KM], floatround_round);
        printf("FLOATR: %d", floatround(Veh[r][KM], floatround_round));// DEBUG
DEBUG .LOG:
Код HTML:
FLOATR: 1
------------
Veh[r][KM] is 0.751, not 1.
Normal should be: 0751.
Reply
#6

Floatround rounds the number to the nearest whole number.
Which will make 0.751 = 1.

If you want to display 0.751 there's no need to use floatround at all.
If you remove floatround and use %f instead of %d it will display 0.751 correctly.
Reply
#7

Quote:
Originally Posted by norton2
Посмотреть сообщение
OK.
Код HTML:
E@_R[Veh[r][ServerID]] = floatround(Veh[r][KM], floatround_round);
        printf("FLOATR: %d", floatround(Veh[r][KM], floatround_round));// DEBUG
DEBUG .LOG:
Код HTML:
FLOATR: 1
------------
Veh[r][KM] is 0.751, not 1.
Normal should be: 0751.
0.751 rounded is in fact 1.
If you want it to be 751 then you need to do it like this:
Код:
E@_R[Veh[r][ServerID]] = floatround(Veh[r][KM] * 1000.0, floatround_round);
        printf("FLOATR: %d", E@_R[Veh[r][ServerID]]);// DEBUG
Though, I don't think the car is going to be going 751 km/h. You probably (depending on your task) need to multiply it by 100.0 instead.
Reply
#8

Crayder, Thank you very much!! +1
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)