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

ascii to float conversion

dear friends

i would like to know how can we convert the ascii values to decimal values to perform some calculations.
my requirement is that i am receiving a six digit ascii data via com port of AT 89c52.now i have to perform some calculations with this value and send back via comport.so first i have tonvert the receiving ASCII value to a float value, then after the necessary calculations i've to convert the result again to ASCII to send via com port.can anyone provide some idea ?

sunish

Parents Reply Children
  • "we have to extract every digits from the float value.how is it possible?"

    This is only possible, if you mean binary digits.

    Every real number can not be exactly stored as a floating point number. Because of this, a floating point value does not always convert exactly to the decimal number you expect.

    The extracted number may for example look like 2.99999999997.

    Because of this, you normally do not want to make an exact extract, but want to round the number to a reasonable number of digits. This is what happens when using sprintf() with the %g conversion - it tries to establish the real number of value digits in the floating point number.