Why is this not working?
#7

Well, a float (%f, %.0f, %.2f...) is a number with decimal fractions included. For example: 5.43, 87.2, 93.59385, 2.00 etc.
However an integer (%i, %d) is just a number with no decimals, or whole numbers. For example: 1, 6, 245, 83 etc.

By adding a decimal value, you are no longer using an integer. 'floatround' will round the FLOAT to the nearest INTEGER. So it basically converts it from %f to %i.

Another example:
If I have a number that is 75.636, that is my current fuel. If I try to use %i, it will think it is an integer. However, as you now know, integers do NOT have decimal values, so the server will be putting a FLOAT into an INTEGER variable. Giving you some random massive number which I cannot currently explain at the moment because I don't understand why either, but it does.
However, if you use floatround, it will convert 75.636 to the nearest whole number, which is 76. Because 75.636 is closer to 76 than 75. So we now have an integer, which can be used properly with %i or %d.

I'm trying to explain it in the easiest way to understand, but I can't tell if I'm doing it right :P

Definition of a float/decimal: "a fraction whose denominator is a power of ten and whose numerator is expressed by figures placed to the right of a decimal point."
Definition of an integer: "a number which is not a fraction; a whole number."
Floatround: "Round a floating point number to an integer value." https://sampwiki.blast.hk/wiki/Floatround
Reply


Messages In This Thread
Why is this not working? - by AnonScripter - 07.02.2014, 04:41
Re: Why is this not working? - by Shockey HD - 07.02.2014, 05:15
Re: Why is this not working? - by [ABK]Antonio - 07.02.2014, 05:26
Re: Why is this not working? - by ProjectMan - 07.02.2014, 05:40
Re: Why is this not working? - by Vince - 07.02.2014, 06:05
Re: Why is this not working? - by AnonScripter - 07.02.2014, 21:56
Re: Why is this not working? - by Threshold - 08.02.2014, 04:45
Re: Why is this not working? - by AnonScripter - 08.02.2014, 09:03

Forum Jump:


Users browsing this thread: 1 Guest(s)