AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Float precision (https://forums.alliedmods.net/showthread.php?t=309960)

adska 08-14-2018 02:20

Float precision
 
Hello, I am using float type variable to save number like 0.01, but when i print it to chat then number is shown as 0.099999. also it is not only print problem, if i make mathematical action between float variables (not very high precision, ex 5 digits after comma) precision of result is lost. why? how to fix it?

klippy 08-14-2018 04:38

Re: Float precision
 
You can't, that's how IEEE754 single precision floating point numbers work, in every language. When formatting strings though you can use %.2f instead of just %f to display 2 digits after the decimal point, for example.


All times are GMT -4. The time now is 12:41.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.