I am currently working on a program where I want to calculate the round value for only 2 digits after floating point Need I say, I have declared
float a; If a = 3.555 will store it a = 3.56 , A = 3.423 , the value of one will be a = 3.423 , there will be no change. I can do this to print output, but what should I do when it is stored in a variable and uses that variable for any other calculation?
Do not use floating point if you need two digits, decimal point. Use a fixed point number instead. For example, just use an integer that is 100 times greater than the decimal number that you want to represent. Trying to fit the base 2 floating point number into rounding rules is not just satisfactory results for you.
Comments
Post a Comment