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

VARIABLE TYPE CONVERTION PROBLEM

I AM GETTING SOME DATA FROM TEMPERATURE SENSOR.

IT IS A DOUBLE DATA TYPE. IS IT POSSIBLE TO CHANGE IT TO LONG OR INT DATA. AND JUST KEEP THE INTEGER PARTS.

THX

  • 1. Disable your CAPS LOCK!
    2. Yes. If you really get the value as a Keil-supported floating point value then you should need only cast the float type to an int type. E.g.

    float        tempSensorValue = readTempSensor() /* ??? */;
    int          integer         = (int) tempSensorValue;
    unsigned int fraction        = (unsigned int) (1000 * (tempSensorValue - integer));
    
    printf("Result is %d.%u\n", integer, fraction);
    What temperature sensor gives you floating point values? Do you really mean an ASCII string that looks like a floating point number?

  • Hi ry uran,
    may i know whether you are using C51/8051 for your programming? Because I am doing a temperature sensor but using 8051 micro-controller.

    From
    jepthah