Horner 13 Posted February 3, 2013 Just trying to grab the damn decimals in a number, but no.. _num = (100 + 0.123); _num = _num - (floor _num); player groupChat (str _num); This prints out "0.123001" When I print out "(100 + 0.123)" it prints out correctly, is it floor that isn't working? Is there any way to get a true exact value out of this? I'd just like 100.123 - 100 to evaluate properly. Share this post Link to post Share on other sites
ceeeb 147 Posted February 3, 2013 Try _num mod 1 Arma stores numbers single precision floating point numbers, which can cause unexpected and imprecise results, especially when using extremely large or extremely small numbers. Share this post Link to post Share on other sites
squeeze 22 Posted February 3, 2013 the way I've always done it, not for the same reason though. _num = (100 + .123); _num = (floor(((_num - (floor _num))*1000) mod 1000))/1000; player groupChat (str _num); Share this post Link to post Share on other sites
Horner 13 Posted February 3, 2013 Sad thing is it doesn't fluctuate for all numbers, Squeeze, and _num mod 1 has the same effect as floor, ceeeb. Share this post Link to post Share on other sites
panther42 52 Posted February 3, 2013 Horner, have you tried CBA_fnc_formatNumber? Used in a trigger, this seems to get what you want: null = [] spawn {_num = (100 + 0.123); _num = _num - (floor _num); player groupChat (str _num); test = [_num, 1, 3] call CBA_fnc_formatNumber; player groupChat test;}; Share this post Link to post Share on other sites
ceeeb 147 Posted February 3, 2013 Please look into floating point numbers Horner (I went through the same confusion myself some years ago). They can not store all decimal numbers precisely, and round off to the nearest possible value. http://en.wikipedia.org/wiki/Floating_point - Wikipedia article on floating point numbers http://www.h-schmidt.net/FloatConverter/IEEE754.html - online Java tool to convert decimal to floating point numbers. Note that 100.123 is not a value that can be stored as a floating point number (closest possible number is 100.123001) Share this post Link to post Share on other sites
Horner 13 Posted February 3, 2013 @panther, I'm actually working on a different number formatting system than CBA because of how the "mod" operator starts to spit out odd values after 100 billion (I've managed to fix that). But I could look into formatNumber for adding decimals. Thanks. @ceeeb, Thanks for the documentation on that, I'll read up, I'm aware now that arma uses float values but it seems to only mess up when using operators other than the standard + - * /. Share this post Link to post Share on other sites