Raised This Month: $51 Target: $400
 12% 

Float precision


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
adska
Junior Member
Join Date: Jul 2018
Old 08-14-2018 , 02:20   Float precision
Reply With Quote #1

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?

Last edited by adska; 08-14-2018 at 02:20.
adska is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-14-2018 , 04:38   Re: Float precision
Reply With Quote #2

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

Last edited by klippy; 08-14-2018 at 04:40.
klippy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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