hi everyone; i am using a float value for my calculation eg: weight = 999.99 (ideally) but float weight = 999.989999 (by float data type as we get 6 digits after decimal) i am not displaying this value but i want to use weight = 999.99 for my calculation. thus how to truncate as well as roundoff it upto 2 digits after decimal thank u all
I would suggest you don't use floats at all. Just work in (integer) units * 100 and when you need to display the value stick the decimal point in manually.
This gives a whole heap of benifits in terms of speed and program size on an 8051.
1) Use integers whenever you can. 2) Look into the %g formatting character. 3) Look through the math functions available. 4) Try Google - this is a generic question with a huge number of answers...