I have a double which has actual value (as seen from the debugger) val = 1.5530000000000002
however if I print it like string.Format("{0}", val) I get “1.553” which is realistic value I am looking for.
the 1.5530000000000002 comes from some socket API and I cant change that. But I need 1.553..
what shall I do?
Please note I receive thousands of these per sec. I can’t afford tinkering with the Math class or converting them forth and back. any consolations?
I decided to upscale them to ints. I can do it because I know how many significant digits are in the number.
I am sure decimals will be slower simply because I dont have x128 CPU and memory bus. Using Math is out questions ever.
sorry for the blur with casting to float earlier.
EDIT OK. So I got that SO now is not free anymore. Each question need now attention which is costly in time… Here is the code which answers why I will not use Decimals and Math.
first part – is Math, second is what I am intended to use (conversion to int), and the third is Decimals.
The results on my i7 as follows – 12K ticks, 700 ticks, 35K ticks respectively.