This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

float truncation

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

Parents
  • 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.

Reply
  • 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.

Children